I know well, what is a class literal in java, I just wonder, what is the reason for the .class in the syntax. Is there any ambiguity removed by this? I mean, wouldn’t an alternative Java syntax using
Class<String> c = String;
instead of
Class<String> c = String.class;
work? To me the class keyword looks like a boilerplate.
Sure, you could make that the syntax. But using the
.classsuffix makes the compiler’s job easier; it has to do less work to know that the code is syntactically correct.Without the suffix, the compiler would have to work harder to understand the difference between this:
and this:
If you don’t think that the
.classsuffix is needed, do you also think that thefandLsuffices are useless (forfloatandlongliterals, respectively)?