Joe Soltzberg

66%
Flag icon
So when should you use boxed primitives? They have several legitimate uses. The first is as elements, keys, and values in collections. You can’t put primitives in collections, so you’re forced to use boxed primitives. This is a special case of a more general one. You must use boxed primitives as type parameters in parameterized types and methods (Chapter 5), because the language does not permit you to use primitives. For example, you cannot declare a variable to be of type ThreadLocal<int>, so you must use ThreadLocal<Integer> instead. Finally, you must use boxed primitives when making ...more
Joe Soltzberg
Historically I think a lot of people used them to represent the absence of a value since you can't have a null int
Effective Java
Rate this book
Clear rating
Open Preview