'Using 'default' as a variable
Hello I have an object that has the value "default". But I can't do it because it gives error: Identifier expected.I receive this object from a service and I cannot modify the values. https://developers.braintreepayments.com/reference/response/credit-card/node#default
private String default; or private Boolean default;
I want to do getter and setter.
Any way to solve?
Solution 1:[1]
It can't be solved, because it's not a problem. It's a rule. You can't use a keyword as a variable name. what do you mean by "I receive this object from a service and I cannot modify the values.". you are getting a json object, right?. Just parse it to a different variable name.
Solution 2:[2]
I ran into the same issue where I needed to use the 'default' and 'ref' as class members in order to create objects because the server would require this format. I got no solution to define members with these name, so I ended up creating a list that would create static strings as required (with default and ref in them) based on conditions (parameters passed while creating objects).
This is a work around to live with in case you cannot get the other side to stop using these names.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ismail Shaikh |
| Solution 2 | ZalimCode |
