4 ms·
I don't understand google's awful implementations. In my code by contrast, a map function looks like this: public double foo(double x) { return x*x;
by mynameishere 17y ago
I don't understand google's awful implementations. In my code by contrast, a map function looks like this:
public double foo(double x)
{
return x*x;
}
list=Utility.map(this,"foo",list);
- jimbokun 17y agoYou need to do reflection, which probably has performance implications. You also cannot do closures, which you can simulate with anonymous inner classes. Might be worth the trade off in your case, but maybe not for the cases Google has in mind.
- brunomlopes 17y agoNot only does that require reflection, it is very error prone and not refactor-friendly. Just change the type of the list, change the method, and it will blow up on runtime instead of compile time. In my opinion, that goes against the grain of Java (and c#, in a way) of having the compiler doing a lot of checking for you. Google's approach, while more verbose, is a bit safer and more idiomatic.
- bfung 17y agoIn addition to the other comments, the Utility class used in this example defeats the purpose of OO programming that Java is more in tune with. What's to stop the proliferation of these Util classes with static methods? I believe the more Java way would be to extend the List interface to add a map method and implement a corresponding class. To make this less of a pain, extend from one of the JDK provided classes if possible... but yes, it's still a pain.