Android ART can’t set final fields correctly

January 2016

For example you have class Person. Person is a POJO for REST-service (for instance, for using with retrofit).

This line of code creates two read-only fields. It’s necessary to assign initial values because every field is final. But there’s another way to do the same thing:

It’s hard to believe, but second – is the only right way to create class.

For example, you’re creating class instance:

I think it depends on JVM but it’s truth for Android ART.

Leave a Reply

Your email address will not be published. Required fields are marked *