Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ptp-dev] Question about use of generic types

Dave,

First off, I'd highly recommend the book "Java Generics and Collection"
by Naftalin & Wadler, published by O'Reilly.

Personally, I would try to get rid of the warnings by supplying the
generics parameters.  I can't know whether the 
IAttributeDefinition<?, ?, ?> is the best choice for any given
situation.  If you know the exact types for the three question marks,
I would use them instead, or better yet, the precise class that
implements IAttributeDefinition<...> (BooleanAttributeDefinition in the
example that follows).

In org.eclipse.ptp.rtsystem.AbstractProxyRuntimeSystem.java, line 775,
we define

   IAttributeDefinition<?,?,?> attrDef = null;

since several blocks of code will supply different explicit
attribute definitions with different types where the question marks are.
At line 786 we use the above declaration of attrDef to store its value,

   attrDef = attrDefManager.createBooleanAttributeDefinition(attrId,
                 attrName, attrDesc, defVal);

We know that in this point that the instance of attrDef is really a
BooleanAttributeDefinition.  We could have used another variable to
receive the return value from the method call declared either as a

   BooleanAttributeDefintion anotherAttrDef;

or as an

   IAttributeDefinition<Boolean,BooleanAttribute,
                        BooleanAttributeDefinition> anotherAttrDef;

Since you are using BooleanAttributeDefinition in both cases,
I would prefer the former over the latter.

Of course the other blocks of the code would barf with attrDef defined
as anotherAttrDef above, since those blocks create other types of
attribute definitions to set attrDef's value.

The reason for the recursive definition of BooleanAttributeDefinition,
i.e.

public final class BooleanAttributeDefinition
  extends AbstractAttributeDefinition<Boolean,BooleanAttribute,
                                    BooleanAttributeDefinition> {
   ...
}

is a bit difficult to explain in one email.  I would suggest looking
at the O'Reilly book, as it does a good job of explaining this idiom.

I hope this helps.

Regards,
Randy

On Tue, 2007-07-17 at 13:00 -0400, Dave Wootton wrote: 
> Randy
> I'm trying to crean up warning messages in my code and am looking at 
> warnings such as 'IAttribute is a raw type. References to generic type 
> IAttribute<T, A, D> should be parameterized'.  I haven't used generics 
> much beyond simple stuff like Vector<String> so am not sure I understand 
> how I should code this to get rid of the warning. I found one place where 
> you had code 'IAttribute<?, ?, ?>', which if I do the same, gets rid of 
> the error message. However, I'm not sure I'm doing the right thing by 
> coding that.
> 
> Is there some specific way I should code this or should I just accept the 
> warning?
> 
> Thanks
> Dave
> _______________________________________________
> ptp-dev mailing list
> ptp-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/ptp-dev



Back to the top