Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return Tuple from Java Method

Tags:

java

tuples

I wrote a java class:

public class Tuple<X, Y> { 
  public final X x; 
  public final Y y; 
  public Tuple(X x, Y y) { 
    this.x = x; 
    this.y = y; 
  } 
}

but when I create a function like this:

public Tuple<boolean, String> getResult()
{
    try {
        if(something.equals(something2))
             return new Tuple(true, null);
    }
    catch (Exception e){
        return new Tuple(false, e.getMessage());
}

However, I get the following compilation error:

unexpected type
  required: reference
  found:    boolean

What I can do?

like image 810
a1204773 Avatar asked May 31 '13 22:05

a1204773


1 Answers

Generics aren't for primitive types. Use Boolean instead of boolean.

public Tuple<Boolean, String> getResult() {
    //your code goes here...
}
like image 160
Luiggi Mendoza Avatar answered Sep 18 '22 11:09

Luiggi Mendoza