Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

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