Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java - Cannot convert Integer to int

Tags:

java

I am stuck at this problem for ages. Basically I cannot convert Integer to int.

class CheckOdd implements Check<Integer>
{
  public <Integer> boolean check(Integer num)
  {
    int i = (Integer) num;
    return (i % 2 != 0);
  }
}

I have tried using
int i = (Integer) object; int i = (int) object; intValue()
but still no luck. If I use int i = (Integer) object; it produce error:incompatible types. If I use int i = (int) object; it produce error: inconvertible types.

Please Help. Thank you in advance.

like image 727
user2875021 Avatar asked Dec 12 '22 02:12

user2875021


1 Answers

You've replaced java.lang.Integer with a generic type which you have named Integer

public <Integer> boolean check(Integer num) // <-- not a java.lang.Integer

should be

public boolean check(Integer num)
like image 119
Elliott Frisch Avatar answered Dec 13 '22 15:12

Elliott Frisch