3 ms·
I agree with the argument that more detail is conveyed in its verbosity. But I fail to understand how type inference (like that seen in Scala, C# etc... doesn'
by samirahmed 15y ago
I agree with the argument that more detail is conveyed in its verbosity.
But I fail to understand how type inference (like that seen in Scala, C# etc... doesn't clean up the verbose)
for example,
HashMap<String,ArrayList<String>> map = new HashMap<String,ArrayList<String>> ();
versus
val map = new HashMap<String,ArrayList<String>> ();
The latter conveys just as much information
- MatthewPhillips 15y agoYes but val map = GetMap(); does not.
- AndrewDucker 15y agoIt does when you can hover your cursor over GetMap() and see the exact specification for it.
- samirahmed 15y agoAs the programmer, you wouldn't call getMap if you didn't know the return type As the reader, this situation would be analogous to looking up the what map is, assuming it was declared earlier ... is a datamember etc. something that might as well arise when typing.. private HashMap<Integer, String> map ; then 30 lines later this.map = getMap(); You would have to check javadocs or function header some time
- coopernurse 15y agoAgreed. Once you use a language with type inference it's hard to go back to Java. Java also lacks properties, which results in boilerplate getter/setters if you want to follow idiomatic convention (you could make all the member variables public, but your coworkers would probably shun you).
- benjiweber 15y agoThere are alternatives. e.g. a public final Property<String> Name = new Property<String>(); Where Property defines a .get() and a .set(); However, getters and setters are generally a code smell. It's better to be telling objects to do things rather than ask them for information. Modern Serialization & Injection frameworks no longer require getters/setters.
- benjiweber 15y agoYou can now do HashMap<String,ArrayList<String>> map = new HashMap<>(); in Java 7 http://docs.oracle.com/javase/tutorial/java/generics/gentypes.html#diamond http://docs.oracle.com/javase/tutorial/java/generics/gentype...