You are creating a variable with the name Float
. That's all. It's not a reserved word. The compiler is not trying to interpret it as a class name due to the syntax of your statement. It's not invalid, even if it is bad form.
Why does Java not complain about the reserve word Float?
-
16-01-2022 - |
Question
I entered this in Eclipse and expected it to be the wrong syntax but it is allowed. Can someone please explain what is happening here? Should the Float
and Integer
keyword not be reserved? What type of assignment is this?
Number Float = 99.455f;
Number Integer = 2;
Solution 2
OTHER TIPS
No, Float
is not reserved word. float
is reserved word. Here is list of reserved words in java
because that isn't reserved, it is autoboxed.
Float(which is a wrapper class) isn't Java reserved keyword but float(which is a primitive) is.
Java is case sensitive, float
is reserved keyword but Float
not.
Float
is not a reserved word. It is just a name of java.lang.Float class, and system library class names (even from java.lang
) are not reserved. float
is a reserved word. You can also have
int String = 1;
but I would not advise.
How about these , these also compile. No deference from Float or Integer which are no reserved key words but Class names
String String = "";
Math Math = null;
Object Object = null;