How MySQL Optimises ORDER BY
How MySQL Optimises ORDER BY In some cases MySQL can uses index to satisfy an ORDER BY or GROUP BY request without doing any extra sorting. The index can also be used even if the ORDER BY doesn’t match the index exactly, as long as all the unused index parts and all the extra are […]
Learning the Java Language
Learning the Java Language This trail covers the fundamentals of programming in the Java programming language. Object-Oriented Programming Concepts teaches you the core concepts behind object-oriented programming: objects, messages, classes, and inheritance. This lesson ends by showing you how these concepts translate into code. Feel free to skip this lesson if you are already familiar […]
Packages
Packages This lesson explains how to bundle classes and interfaces into packages, how to use classes that are in packages, and how to arrange your file system so that the compiler can find your source files.
Generics
Generics Generics are a built-in language feature that will make your software more reliable. This lesson discusses the following topics: Introduction This section explains some common shortcomings associated with non-generic code. Specifically, it shows how certain kinds of bugs will crash an application at runtime, since they are not detectable by the compiler. Generic Types […]
Type Erasure
Type Erasure When a generic type is instantiated, the compiler translates those types by a technique called type erasure — a process where the compiler removes all information related to type parameters and type arguments within a class or method. Type erasure enables Java applications that use generics to maintain binary compatibility with Java libraries […]
Wildcards
Wildcards Earlier we mentioned that English is ambiguous. The phrase “animal cage” can reasonably mean “all-animal cage”, but it also suggests an entirely different concept: a cage designed not for any kind of animal, but rather for some kind of animal whose type is unknown. In generics, an unknown type is represented by the wildcard […]
Generic Subtyping
Subtyping As you already know, it’s possible to assign an object of one type to an object of another type provided that the types are compatible. For example, you can assign an Integer to an Object, since Object is one of Integer‘s supertypes: Object someObject = new Object(); Integer someInteger = new Integer(10); someObject = […]
Generic Bounded Type Parameters
Bounded Type Parameters There may be times when you’ll want to restrict the kinds of types that are allowed to be passed to a type parameter. For example, a method that operates on numbers might only want to accept instances of Number or its subclasses. This is what bounded type parameters are for. To declare […]
Generic Methods and Constructors
Generic Methods and Constructors Type parameters can also be declared within method and constructor signatures to create generic methods and generic constructors. This is similar to declaring a generic type, but the type parameter’s scope is limited to the method or constructor in which it’s declared. /** * This version introduces a generic method. */ […]
Generic Types
Generic Types Let’s update our Box class to use generics. We’ll first create a generic type declaration by changing the code “public class Box” to “public class Box<T>“; this introduces one type variable, named T, that can be used anywhere inside the class. This same technique can be applied to interfaces as well. There’s nothing […]