4 ms·
If there's a getter and a setter for a class field, you can just make it public.
by spektom 12y ago
If there's a getter and a setter for a class field, you can just make it public.
- ossreality 12y agowhomp whomp. not really.
- TheLoneWolfling 12y agoThe problem is that in Java at least, you cannot. At least if it will be ever used by code beyond your control. Because then you'll never be able to add a getter or setter later without breaking people's code. Java is frustrating in that regard. As it should be able to deal with automatically invoking getters and setters when needed (it already inlines getters and setters at runtime, this is "just" the reverse), but it's a language decision that it doesn't. As an additional bonus, this would help reduce the (legendary) verbosity of Java. a.b += c.d is much easier to read than a.setB(a.getB() + c.getD()). And don't get me started on Java's generics or lack of operator overloading...