SHARE
TWEET

vararg

DulcetAirman Mar 29th, 2016 (edited) 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ch.fhnw.claudemartin;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Optional;
  6.  
  7. public class SomeClass {
  8.   static void m(final Optional<?>... args) {
  9.     System.out.println("m(" + Arrays.toString(args) + ")");
  10.   }
  11.  
  12.   public static void main(final String[] args) {
  13.     // Integer:
  14.     m(Optional.of(1));
  15.     // String:
  16.     m(Optional.of("a"), Optional.of("b"));
  17.     @SuppressWarnings("unchecked")
  18.     // Long as array:
  19.     final Optional<Long>[] longs = new Optional[] { Optional.of(42L), Optional.of(0L) };
  20.     m(longs);
  21.     // Number as List:
  22.     final List<Optional<Number>> numbers = Arrays.asList(Optional.of(42L), Optional.of(0d));
  23.     m(numbers.toArray(new Optional[numbers.size()]));
  24.   }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top