I feel rejected :)

Dan Smith daniel.smith at oracle.com
Tue Mar 15 16:34:53 PDT 2011


From Gilad's 2004 generics tutorial [1]:

> Now, you might think that all we’ve accomplished is to move the clutter around. Instead of a cast to Integer on line 3, we have Integer as a type parameter on line 1’. However, there is a very big difference here. The compiler can now check the type correctness of the program at compile-time. When we say that myIntList is declared with type List<Integer>, this tells us something about the variable myIntList, which holds true wherever and whenever it is used, and the compiler will guarantee it. In contrast, the cast tells us something the programmer thinks is true at a single point in the code.

The refactoring, unfortunately, doesn't produce something particularly more pretty.  But it's a lot more robust.

—Dan

[1] http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf


On Mar 15, 2011, at 1:46 PM, Les Stroud wrote:

> Not to butt in, but I’m not sure which one is 'less pretty', the xml version or the lisp version (<<<< vs ((( ) :)
> 
> LES
> 
> On Mar 15, 2011, at 4:32 PM, Neal Gafter wrote:
> 
>> Rémi-
>> 
>> I don't like casts either.  Did you mean
>> *
>>   public interface Folder<T> {
>>       public T fold(T a, T b);
>>   }
>> 
>>   public static <T extends Comparable<? super T>> Folder<T> max() {
>>     return #{ a, b -> a.compareTo(b)<0 ? b : a };
>>   }*
>> 
>> Cheers,
>> Neal
>> 
>> On Tue, Mar 15, 2011 at 8:41 AM, Rémi Forax <forax at univ-mlv.fr> wrote:
>> 
>>> And this one crash the compiler:
>>> 
>>>   public interface Folder<T> {
>>>       public T fold(T a, T b);
>>>   }
>>> 
>>>   public static <T> Folder<T> max() {
>>>     return #{ a, b -> (((Comparable)a).compareTo(b)<0)? b: a };
>>>   }
>>> 
>>> It doesn't like the cast in the lambda.
>>> 
>>> Rémi
>>> 
>>> 
>>> 
>> 
> 
> 
> --
> Les Stroud Developer, Architect, Creative Thinker
> web: lesstroud.com email: les at lesstroud.com	linked in | twitter | facebook
> 
> 
> 
> 
> 



More information about the lambda-dev mailing list