i have following class:
package query; public class predicate<t> { private string operand1; private string operator; private t operand2; private class<t> classtype; public predicate(string operand1, t operand2, class<t> classtype){ this(operand1, "=", operand2, classtype); } public predicate(string operand1, string operator, t operand2, class<t> classtype){ this.operand1 = operand1; this.operator = operator; this.operand2 = operand2; this.classtype = classtype; } public string getoperand1() { return operand1; } public string getoperator() { return operator; } public t getoperand2() { return operand2; } public class<t> getclasstype() { return classtype; } @override public string tostring() { return operand1 + " " + operator + " ?"; } }
the following line compiles fine:
predicate<string> p1 = new predicate<>("given_name", "=", "kim", string.class);
however, following not:
predicate<integer> p1 = new predicate<>("id", "=", "1", integer.class);
the compiler mentions: cannot infer type arguments predicate<>
what wrong / how can solve this?
"1" string , incompatible integer.class
new predicate<>("id", "=", 1, integer.class)
should ok
or
new predicate<>("id", "=", "1", string.class)
Comments
Post a Comment