hadoop-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Julia Smith <invisible...@mac.com>
Subject Re: specification of type params in org.apache.hadoop.io.*Writable impls
Date Tue, 30 Mar 2010 01:21:18 GMT
Java Generics are finicky. Basically the parameterized generic is not considered the same thing
(type) as a class extended from it. I went through this when writing a deeply generic-ed package
just to test its limits with a heavily templatized c++ package.

On Mar 29, 2010, at 4:06 PM, Andy Schlaikjer wrote:

> Can anyone comment on why the base *Writable implementations (e.g.
> IntWritable, LongWritable, etc) don't specify WritableComparable<T>'s
> type param T?
> 
> I noticed this when I tried to use DoubleWritable [1] within a custom
> WritableComparable parameterized type which constrains its own type
> params:
> 
> public class Pair<
>  First extends WritableComparable<First>,
>  Second extends WritableComparable<Second>>
>  implements WritableComparable<Pair<First, Second>> {
> ...
> }
> 
> With this declaration, something like the following will not compile:
> 
> Pair<DoubleWritable, DoubleWritable> pair = null;
> 
> ERROR: Bound mismatch: The type DoubleWritable is not a valid
> substitute for the bounded parameter <First extends
> WritableComparable<First>> of the type Pair<First,Second>
> 
> However, if DoubleWritable were declared as follows, the above line
> would work just fine:
> 
> public class DoubleWritable implements WritableComparable<DoubleWritable> {
> ...
> }
> 
> [1] http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/io/DoubleWritable.java?revision=786726&view=markup
> 
> Best,


Mime
View raw message