Skip to content

Instantly share code, notes, and snippets.

@adrianshum
Created September 20, 2016 09:50
Show Gist options
  • Select an option

  • Save adrianshum/6a4a8617c548c876571bf673cf434f25 to your computer and use it in GitHub Desktop.

Select an option

Save adrianshum/6a4a8617c548c876571bf673cf434f25 to your computer and use it in GitHub Desktop.
Multi-Bound Type Param Example
import java.util.*;
import java.io.*;
public class Foo {
public static void main(String[] args) throws Exception{
RandomAccessFile input1 = new RandomAccessFile("c:\\temp\\Foo.java", "rw");
System.out.println("1" + read(input1));
DataInputStream input2 = new DataInputStream(new FileInputStream("c:\\temp\\Foo.java"));
System.out.println("2" + read(input2));
}
private static <I extends DataInput & Closeable> String read(I source) {
try (I input = source) {
return input.readLine();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment