fork download
  1. class Ideone {
  2. public static void main(String[] args) {
  3. final Test<String> testString = new Test<>();
  4. final String tString = testString.doSomethingWithT("Hello");
  5. System.out.println(tString);
  6. // will not compile since 1 is not a String:
  7. // int tInt = testString.doSomethingWithT(1);
  8. final String uString = testString.doSomethingWithU("World!");
  9. System.out.println(uString);
  10. final int uInt = testString.doSomethingWithU(1);
  11. System.out.println(uInt);
  12. }
  13. }
  14.  
  15. class Test<T> {
  16. public T doSomethingWithT(T t) {
  17. return t;
  18. }
  19.  
  20. public <U> U doSomethingWithU(U u) {
  21. return u;
  22. }
  23. }
Success #stdin #stdout 0.08s 46836KB
stdin
Standard input is empty
stdout
Hello
World!
1