0

I read some answers w.r.t using getter/setter in Java instead of a public field. Also I know in C# you can use public field and w/ or w/o getter/setter.

Here my question is: if I use a public field without getter/setter in a POJO in Java, will it cause any real runtime issue (e.g., will it cause failure of reflecting/Srping/AOP/certain JSON parser/EJB etc)? Let's put aside performance, readability etc.

Leon
  • 3,124
  • 31
  • 36
  • But then did you try using it? Did it cause any such issue? – Naman Sep 30 '17 at 01:53
  • This question has been answered in this post https://stackoverflow.com/questions/7455630/is-it-necessary-to-have-getters-and-setters-in-pojos – Mohamed Chaawa Sep 30 '17 at 01:54
  • Worth a read. https://stackoverflow.com/questions/46406119/effective-java-item-14-you-can-t-change-the-representation-without-changing-the – OneCricketeer Sep 30 '17 at 01:55
  • @nullpointer No I have not found any issue with public field, but I have not tried intensive frameworks/tools. – Leon Sep 30 '17 at 01:59
  • 1
    This seems too broad. There doesn't seem to be any limit on what frameworks should be considered. How can you answer it except to say if you don't follow standards you make get bitten? But if you limit it to spring then it is answerable. – Nathan Hughes Sep 30 '17 at 01:59
  • In a small "toy" or demonstration program, this should not be an issue. However, it may not scale up very well. – Hovercraft Full Of Eels Sep 30 '17 at 01:59
  • I just want to hear for "famous" frameworks which might be used in projects. I know there is no deterministic answer. – Leon Sep 30 '17 at 02:04
  • 1
    Questions on SO should be answerable definitively. This is too broad. When you're writing code to work with frameworks and libraries is not the time to be a nonconformist. – Nathan Hughes Sep 30 '17 at 02:12
  • 1
    You should try it out for yourself. But since there is almost universal agreement in the Java world that leaky abstractions (like public variables) are a bad thing, I would be *surprised* to see framework builders spending much effort support this. And you are unlikely to find anyone who can advise you on this ... 'cos *sensible* people don't write Java code like that. – Stephen C Sep 30 '17 at 02:12

0 Answers0