0

I want to make a pojo class in which I am binding a json object using ObjectMapper. I have to use a variable name

private String package;

but the above line showing me error. Is there any solution so that I can use this variable name package.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ASK
  • 1,136
  • 1
  • 10
  • 14
  • 2
    You cannot use [Reserved Names](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html) in Java to name stuff in your code. It's prohibited – Vüsal Feb 15 '19 at 09:09
  • the above line showing me error. This really doesn't tell us anything. your problem is that 'package' is a keyword, and thus can not be used as a name for a variable – Stultuske Feb 15 '19 at 09:10
  • `package` is a reserved keyword. You can change slightly and use words like `_package`, `Package` and so on. – Jai Feb 15 '19 at 09:10
  • Yes, I am well aware about the reserved keywords of java. But I was asking whether is there any solution for my problem. – ASK Feb 15 '19 at 10:13

4 Answers4

4

as said in previous comment, package cannot be used in java as a variable name but you can annotate the variable to still use that name in JSON

@JsonProperty("package")
private String packageName
Wisthler
  • 577
  • 3
  • 13
2

The word package is a keyword and you can't use it as a name for variable.

Here's a link to a list of keywords in java

Andree Kröger
  • 84
  • 1
  • 1
  • 5
0

Reserved words are words that can not be used as names of objects or variables in a Java program because they are already used by the syntax of the Java programming language.

Package is also a Reserved word.

If you try to use any of the following words as identifiers in your Java programs, you will get an error.

Rukshan
  • 127
  • 1
  • 12
0

You can't use the names to declare that are used in Java language.