6 ms·
I had to implement a Java REPL like this one in school. My experience of using it is that tells me that without a undefined type keyword it becomes very boring
by arturventura 11y ago
I had to implement a Java REPL like this one in school.
My experience of using it is that tells me that without a undefined type keyword it becomes very boring to use. Each time you have to define a variable you have to write all type info:
Map<String,String> foo = new HashMap<>();
If java had a inferred type declaration, like Golang, Swift, Scala, etc. This would be much simpler:
var foo = new HashMap<String,String>();
But from what I think there is nothing like that on Java's roadmap. In fact, I think it was proposed and rejected in the past.
- josho 11y agoWhat's wrong with simply: Object foo = ... Not quite var, and it would require the interpreter to do a little bit more work when invoking methods to avoid the necessary downcasting.
- Alphasite_ 11y agoBecause you're sacrificing consistancy and type safety for object to avoid increasing the syntax which feels like optimising for the wrong metric.
- jonathankoren 11y agoIt's a REPL! It's for debugging. If you're not optimizing for ease of use, you're optimizing for the wrong metric.
- lgas 11y agoYou could also just add support for the "var x =" notation into the REPL as a preprocessing step that translates it to the appropriate typed representation.
- 67726e 11y agoI get why that would be nice, but it feels kinda wrong for what Java is[0]. That's why if I need to quickly bang out or test something I use my Scala REPL. [0] - http://programmers.stackexchange.com/a/184183/7007 http://programmers.stackexchange.com/a/184183/7007
- kedean 11y agoJava can do the reverse, infer an implementations generic types from the declaration. Map<String, String> foo = new HashMap<>();