Implicit 'this' return for void methods (original) (raw)
Marek Kozieł develop4lasu at gmail.com
Fri Mar 28 15:52:30 UTC 2014
- Previous message: Implicit 'this' return for void methods
- Next message: Implicit 'this' return for void methods
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi, I really do not know why some proposals are restored back from the grave, without answering for questions that was already made: http://mail.openjdk.java.net/pipermail/jdk8-dev/2011-December/000382.html
2014-03-28 12:37 GMT+01:00 Ulf Zibis <Ulf.Zibis at cosoco.de>:
Am 28.03.2014 11:05, schrieb Florian Weimer:
String mySub = myVeryLongNamedString.substring(.indexOf("C"),.indexOf("Q")); You can already write String mySub = apply(myVeryLongNamedString, (s) -> s.substring(s.indexOf("C"), s.indexOf("Q"))) with a helper function like this: public static <T, R> R apply(T value, Function<T, R> func) { return func.apply(value); } You don't even need to repeat the type. But the explicit version isn't too bad, either: String mySub; { String s = myVeryLongNamedString; mySub = s.substring(s.indexOf("C"), s.indexOf("Q")); } So I'm not sure if leading dot expressions are all that helpful. Hm, nice hacks, but don't you notice the difference in readability and total amount of code lines in comparison to my proposed one-liner? IMHO the more lines/characters a code has, the more effort is needed to (1) read it and (2) understand it's sense. BTW, our 2nd example wouldn't work as expression in for loop arguments. But what for do we discuss the "leading dot expressions" such exhaustive, if there still is no conviction to add the simple "chaining syntax" to the Java language at all? -Ulf
-- Pozdrawiam Marek Kozieł ( Lasu )
http://na-chlodno.blogspot.com/ http://lasu2string.blogspot.com/
- Previous message: Implicit 'this' return for void methods
- Next message: Implicit 'this' return for void methods
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]