Pacerier
Pacerier

Reputation: 89753

Java Keywords as a variable

In VB.NET, we can surround a variable name with brackets and use keywords as variable names, like this:

Dim [new] As String = ""

C# equivalent:

string @new = "";

I was wondering is there a Java equivalent to doing this?

Upvotes: 10

Views: 6467

Answers (7)

Elbashir Saror
Elbashir Saror

Reputation: 352

you can use the keyword @SerializedName("keyword"). it will map Json node to the keyword specified when you receive a response from the server.

Upvotes: 1

Phil
Phil

Reputation: 3520

No, you cannot do that in Java.

Upvotes: 3

r0ast3d
r0ast3d

Reputation: 2635

Welcome to the world of java.

The simple answer is , that is not possible.

Please read the specification for declaring variable names

http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html

Tut on variable declaration. http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html

List of banned keywords that should be used as variables . http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

Cheers and keep learning!

Upvotes: 3

Piyush Mattoo
Piyush Mattoo

Reputation: 16143

You cannot use Java keywords as variables, method or class names.

Upvotes: 2

Mike Adler
Mike Adler

Reputation: 1200

No. You can add an underscores or somesuch nonsense, but basically keywords are off limits.

Upvotes: 10

ibid
ibid

Reputation: 3902

Tricks like goTo and goto_ are, of course, possible.

Upvotes: 4

Dave Newton
Dave Newton

Reputation: 160271

Nope.

Although you can do horrible things like this:

String String = "String";

If you wanted to be evil, you could use a unicode character and fake it.

Upvotes: 0

Related Questions