singleLines.java 679 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. List<?> myList = new LinkedList<Fruit>();
  2. myList.add(null); // ok
  3. myList.add(new Fruit()); // Compiler error
  4. try {
  5. // your code
  6. } catch (Exception ex) {
  7. // Gotcha!
  8. }
  9. /* *
  10. * The foo method.
  11. *
  12. * @throws UniverseExplodeException when the universe
  13. * is going to explode
  14. */
  15. public void foo() throws UniverseExplodeException {
  16. if (true) {
  17. throw new UniverseExplodeException();
  18. }
  19. }
  20. /**
  21. * Generic version of the Box class.
  22. *
  23. * @param <T> the type of the value being boxed
  24. */
  25. public class Box<T> {
  26. // T stands for "Type"
  27. private T t;
  28. public void set(T t) {
  29. this.t = t;
  30. }
  31. public T get() {
  32. return t;
  33. }
  34. }