Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » geneircs problem either with Eclipse or with me
geneircs problem either with Eclipse or with me [message #256556] Fri, 19 September 2008 14:42 Go to next message
Garret Wilson is currently offline Garret WilsonFriend
Messages: 2
Registered: July 2009
Junior Member
I'm pretty darn sharp on generics, but some things are befuddling me. I
have what seems to be a generics bug on Eclipse, but maybe my expectations
and/or understanding of generics is wrong. Please point me in the right
direction, including directing me to another forum if appropriate.

Suppose I'm creating a parser for a file format that uses CustomType<V>,
where V is the Java value type used to represent the value of the custom
type. I have the idea of a property and value, so that I have a property:

class Property<V, T extends CustomType<V>>
{
public T getType();
public Class<V> getValueClass()
}

And I have a field type that holds a property and value of the type:

class Field<V, T extends CustomType<V>>
{
public Property<V, T> getProperty();
public V getValue();

}

I have an AbstractCustomParser<T extends CustomType<?>>, a base class for
a custom parser that parses any custom type. This parser has an abstract
method to create a field:

protected abstract <V, TT extends T<V>> Field<V, TT> parseField(final
Property<V, TT> property);

This should be straightforward: "I'm going to parse a value for a
property; the value type must be for the same type of value being
returned, and I should return a field for the same type of property I send
in."

So now that I have the base parser set up, I create a parser for "My File
Format". I implement MyCustomType<V> extends CustomType<V>, and I create a
parser for it called MyParser<T extends MyCustomType<?>>. Then I try to
implement the above method:

protected <V, TT extends MyCustomType<V>> Field<V, TT> parseField(final
Property<V, TT> property);

No go!! Eclipse doesn't like this, and tells me that I'm creating a method
that has the same erasure of but doesn't override a parent class method!
It suggests that I should instead use the following:

protected <V, TT extends CustomType<V>> Field<V, TT> parseField(final
Property<V, TT> property);

But this method (defined in AbstractCustomParser<T extends CustomType<?>>)
was created in terms of T (which extends CustomType<?>), so in
MyParser<MyCustomType<?>>, doesn't the "T extends CustomType<?>" turn into
"MyCustomType<?>"?

Either this is an Eclipse bug, or I don't completely understand generics.
If the latter is the case, if you can point me to any book (which I'll
buy) or some online resource that explains this, I'll be grateful.

Sincerely,

Garret
Re: generics problem either with Eclipse or with me [message #256560 is a reply to message #256556] Fri, 19 September 2008 14:45 Go to previous messageGo to next message
Garret Wilson is currently offline Garret WilsonFriend
Messages: 2
Registered: July 2009
Junior Member
(Sorry for the subject-line misspelling. That's what I get when I'm
thinking "this is weird" when I write the word "generics".)

Garret
Re: geneircs problem either with Eclipse or with me [message #256576 is a reply to message #256556] Mon, 22 September 2008 15:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

My comments are really off-topic for Eclipse, but here goes anyway...

Doesn't the complexity of the syntax and difficulty in
understanding/explaining it suggest to you that perhaps this is a
situation where being less clever and more transparent would be a good
idea? Compile-time type checking is nice when it doesn't complicate the
code, but parameterized types (aka, "generics") often make the medicine
of static/early type checking more painful than the "illness" they are
trying to treat. I'd say this is an example of that phenomenon at work.

In other words, maybe the parameterized type code is waaaaay more
complicated than it really needs to be. Personally, I've always held the
philosophy that just because a syntactical feature exists does not
compell one to use it for everything.

Just my $0.02,
Eric


Garret Wilson wrote:
> I'm pretty darn sharp on generics, but some things are befuddling me. I
> have what seems to be a generics bug on Eclipse, but maybe my
> expectations and/or understanding of generics is wrong. Please point me
> in the right direction, including directing me to another forum if
> appropriate.
>
> Suppose I'm creating a parser for a file format that uses CustomType<V>,
> where V is the Java value type used to represent the value of the custom
> type. I have the idea of a property and value, so that I have a property:
>
> class Property<V, T extends CustomType<V>>
> {
> public T getType();
> public Class<V> getValueClass()
> }
>
> And I have a field type that holds a property and value of the type:
>
> class Field<V, T extends CustomType<V>>
> {
> public Property<V, T> getProperty();
> public V getValue();
>
> }
>
> I have an AbstractCustomParser<T extends CustomType<?>>, a base class
> for a custom parser that parses any custom type. This parser has an
> abstract method to create a field:
>
> protected abstract <V, TT extends T<V>> Field<V, TT> parseField(final
> Property<V, TT> property);
>
> This should be straightforward: "I'm going to parse a value for a
> property; the value type must be for the same type of value being
> returned, and I should return a field for the same type of property I
> send in."
>
> So now that I have the base parser set up, I create a parser for "My
> File Format". I implement MyCustomType<V> extends CustomType<V>, and I
> create a parser for it called MyParser<T extends MyCustomType<?>>. Then
> I try to implement the above method:
>
> protected <V, TT extends MyCustomType<V>> Field<V, TT> parseField(final
> Property<V, TT> property);
>
> No go!! Eclipse doesn't like this, and tells me that I'm creating a
> method that has the same erasure of but doesn't override a parent class
> method! It suggests that I should instead use the following:
>
> protected <V, TT extends CustomType<V>> Field<V, TT> parseField(final
> Property<V, TT> property);
>
> But this method (defined in AbstractCustomParser<T extends
> CustomType<?>>) was created in terms of T (which extends CustomType<?>),
> so in MyParser<MyCustomType<?>>, doesn't the "T extends CustomType<?>"
> turn into "MyCustomType<?>"?
>
> Either this is an Eclipse bug, or I don't completely understand
> generics. If the latter is the case, if you can point me to any book
> (which I'll buy) or some online resource that explains this, I'll be
> grateful.
>
> Sincerely,
>
> Garret
>
Re: geneircs problem either with Eclipse or with me [message #256580 is a reply to message #256556] Tue, 23 September 2008 07:12 Go to previous message
Eclipse UserFriend
Originally posted by: mauro.molinari.cardinis.com

Garret Wilson ha scritto:
> Either this is an Eclipse bug, or I don't completely understand
> generics. If the latter is the case, if you can point me to any book
> (which I'll buy) or some online resource that explains this, I'll be
> grateful.
>
> Sincerely,

Hi Garret,
first of all you should try to compile your code with javac to see if
it's an Eclipse compiler bug. If it is, you should open a new bug report
at http://bugs.eclipse.org

Secondly, I can't correctly answer you the question about why Eclipse
suggests:
protected <V, TT extends CustomType<V>> Field<V, TT> parseField(final
Property<V, TT> property);
rather than:
protected <V, TT extends MyCustomType<V>> Field<V, TT> parseField(final
Property<V, TT> property);

Anyway, what sounds a little weird to me is this: you define:
protected abstract <V, TT extends T<V>> Field<V, TT> parseField(final
Property<V, TT> property);

but T in AbstractCustomParser is defined as <T extends CustomType<?>>.

So, suppose you have T = Foo, where Foo extends CustomType<Integer>, the
previous method would "become":
protected abstract <V, TT extends Foo<V>> Field<V, TT> parseField(final
Property<V, TT> property);
but Foo is not a generic type!

This sounds a little tricky to me, maybe it's my problem or maybe
Eclipse is right at saying that this code is not perfectly correct BUT
displays a wrong error message.

I might try the following:

class AbstractCustomParser<T extends CustomType<Y>, Y>
{
protected abstract <TT extends T> Field<Y, TT> parseField(final
Property<Y, TT> property);
}

Hope this can set you on the right direction to solve your issue.

Mauro.
Previous Topic:Re: eclipse platform 3.4 with no ant
Next Topic:Thread tries to get unused buffer / Prints out a lot
Goto Forum:
  


Current Time: Sun Jun 30 13:54:23 GMT 2024

Powered by FUDForum. Page generated in 0.03319 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top