Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Override of abstract generic method!

843793Feb 10 2010 — edited Feb 12 2010
Hi I have this problem:
Generic method in abstract class:

abstract public class AbstractRule {

// method

protected abstract <T> T getvalue();

protected abstract <T> void updateValue(T value);

}


And then let me say , we want to extend this class by adding one filed suppose integer :

public class ExpireLogin extends AbstractRule {

private Integer numberOfLogins;

@Override
public Integer getvalue() {
return numberOfLogins;
}



@Override
public void updateValue(Integer value) {
numberOfLogins=value;
}


}


the first method shows :

- Type safety: The return type Integer for getvalue() from the type ExpireLogin needs unchecked conversion to
conform to T from the type AbstractRule
- implements de.dtnet.swdcore.customer.persistence.domain.AbstractRule.getvalue


the second have a compile error:

- T cannot be resolved to a type
- The method updateValue(T) of type ExpireDaysFromFirstLogin must override or implement a supertype
method


if we change the methods to:


@Override
public <Integer> Integer getvalue() {
return durationInDays;
}

@Override
public <Integer> void updateValue(Integer incValue) {
durationInDays = incValue;
}

the bought are having compile errors

Type mismatch: cannot convert from Integer to java.lang.Integer

Is this possible to be done at all?

I dont like to add a generic to the hole abstract class,
because this will make all to have diferent compile time abstract class, witch i dont like to gain..

Any help would be nice..
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 12 2010
Added on Feb 10 2010
3 comments
3,201 views