We’re converting some .NET 3.5 code to Java (Android).
This Java code gives the error:
Syntax error on token “Chapters”, VariableDeclaratorId expected after this token
this.add (new Book() {Chapters=50, OneBasedBookID = 1,
Long = "Bahai", Short = "ba", Color = c, BookType = b; });
The types are all correct.
Java doesn’t have object initializers, so this syntax is not valid.
Instead, you’re probably looking to do something like this:
Also note that Java has no concept of “proper” properties either, and typical “good” practice is to use getters/setters, and to not name your variables starting with upper-case letters. This wouldn’t work for your
LongandShortmembers though, and overall these practices may not provide any value in your scenario anyway.