java - Type safety error with generic class -


edit: setup

there parser call methods programfactory, factory uses expressions, statements, types , programs seen in header implementation below. programfactory implements iprogramfactory interface looks public interface iprogramfactory<e, s, t, p>

the problem seem have expression generic , not know how right in implementation (in header , in methods)

it seems work when return type of type expression seen here

    @override public expression<boolean> createtrue(sourcelocation sourcelocation) {     true expr = new true();     return expr; } 

but not when variable of type expression

i made wildcards return type , argument type not have same

public abstract class binaryexpression<t, r> extends expression<t>{     expression<r> left;     expression<r> right; } 

in implementation of interface seem have same problem on , on again.

expression raw type. references generic type expression<t> should parameterized 

the problem when parameterize these expressions tell me interface doesn't have method.

the method createaddition(expression<double>, expression<double>, sourcelocation) of type programfactory must override or   implement supertype method 

this implementation looks

@override public expression<double> createaddition(expression left, expression right, sourcelocation sourcelocation) {     addition expr = new addition(left, right);     return expr; } 

this interface looks like

/** expression evaluates sum of given expressions */ e createaddition(e left, e right, sourcelocation sourcelocation); 

this class addition looks like

public class addition extends binaryexpression<double, double>{      public addition(expression<double> left, expression<double> right){         this.left = left;         this.right= right;     }       @override      public double eval() {          double sum = left.eval() + right.eval();          return sum;      } } 

this expression class looks

public abstract class expression<t> {     public abstract t eval(); } 

this header implementation looks like

public class programfactory implements iprogramfactory<expression<?>, statement, type, program>{ 

you didn't provide full interface implementation. can think it's like:

class myimplementation implements interface<expression> {         @override         public expression<double> createaddition(expression left, expression right, sourcelocation sourcelocation) {             addition expr = new addition(left, right);             return expr;         } } 

but should like:

class myimplementation implements interface<expression<double>> {         @override         public expression<double> createaddition(expression<double> left, expression<double> right, sourcelocation sourcelocation) {              addition expr = new addition(left, right);              return expr;         } } 

this raw type expression = |expression<e>|. , using simple expression in method parameters erase type parameter. cannot declare in interface implementation raw expression , override method using parameters type parameter(cte). think type parameters simple alias.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -