vendredi 13 janvier 2017

Final boolean field not initialized when object is created via Reflection

found a strange things today. I have a protected final boolean field:

 protected final boolean active = true;

As you can see, I expect this field to be initialized with TRUE value after object is instantiated. This is a database model class. I use mybatis 3.1.1 to read data from the database. What I see is when I do call to db using mybatis SqlSession.selectOne() I receive an object with active == false! But I don't change this field in sql query. I digged through mybatis code and found that in DefaultObjectFactory.java#create(Class, List>, List) my object is instantiated and has this final 'active' field equal to FALSE. well, I'm totally confused and cannot find any information regarding it. Could someone please explain what's going on here? as I thought that final field must be initialized after constructor logic is over.





Aucun commentaire:

Enregistrer un commentaire