0

I'm trying to use a triple to return multiple values but I get "cannot instantiate the type Triple" I tried multiple things but nothing worked. What is the correct Syntax?

import org.apache.commons.lang3.tuple.Triple;

private static Triple<String, String, String> test() {
    Triple<String, String, String> triple = new Triple<>();
    ...
    return triple;
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Danny
  • 1
  • 1

1 Answers1

5

Triple is abstract, use MutableTriple or ImmutableTriple instead.

  • With ImmutableTriple I get "Cannot infer type arguments for ImmutableTriple<>" – Danny Aug 07 '20 at 10:10
  • Then you could explicitly specify the type parameters, like we did in the good old days of Java 6. –  Aug 07 '20 at 10:29
  • 1
    `ImmutableTriple` requires 3 values to be specified in the constructor. –  Aug 07 '20 at 10:34
  • 1
    `ImmutableTriple triple = new ImmutableTriple(a, b, c);` or `ImmutableTriple triple = ImmutableTriple.of(a, b, c);` – Jeroen Steenbeeke Aug 07 '20 at 10:52