Generic Classes and Methods

Descrição

Masters of Science Programming 2 FlashCards sobre Generic Classes and Methods, criado por Nathan Hunsdale em 01-06-2014.
Nathan Hunsdale
FlashCards por Nathan Hunsdale, atualizado more than 1 year ago
Nathan Hunsdale
Criado por Nathan Hunsdale quase 10 anos atrás
86
0

Resumo de Recurso

Questão Responda
Generics are a facility of generic programming that was added to Java as part of _____ J2SE.5.0
They allow a type or method to operate on objects of various _____ types
Generics also provides _____-_____ type saftey compile-time
Generics The Motivation No matter how careful one is at programming, _____ will always exist bugs
Generics The Motivation ______-______ bugs tell you immediately that something wrong Compile-time
Generics The Motivation ______ bugs are much more problematic as they don't always surface _____. When they do surface, it might be at a time that is far removed from where the bug originated RUNTIME bugs are much more problematic as they don't always surface IMMEDIATELY. When they do surface, it might be at a time that is far removed from where the bug originated
Generics The Motivation Generics add _____ to your code by making more of your bugs detectable at _____-_____ Generics adds STABILITY to your code by making more of your bugs detectable at COMPILE-TIME
Generics The Motivation Error Catching The main motivation is to generate _____-_____ errors rather than _____ errors The main motivation is to generate compile-time errors rather than Runtime errors
Generics The Motivation Replacement for Method Overloading Overloaded methods are often used to perform similar operations on different types of _____ data
Generics The Motivation What is an overloaded method? A method that is declared more than once and each time it is declared, it is to handle a different type of data
Generics The Motivation e.g. 2 overloaded methods could be replaced with one method that accepts a non-specific _____ parameter
Generics The Motivation An example of how to replace 2 overloaded methods with one generic method
Generics Implementation and Compile-Time Translation Based on the types of the arguments passed to the _____ _____,the compiler handles each method call appropriately generic method
Generics Implementation and Compile-Time Translation Create a generic method called printMe() public static <T> void printMe(T[] myArray){ ..... }
Generics Implementation and Compile-Time Translation The <T> marks the method as being _____ and specifies the name of the <T> parameter that will be used in the definition generic
Generics The Motivation It will only serve as a replacement for overloaded methods that perform the exact same _____ function
Generics When the compiler translates a generic method into Java bytecodes, it removes the type parameter and replaces with actual types. This process is known as _____ Erasure
Type parameters used in a method's parameter list The type-parameter names throughout the method declaration must match those declared in the _____-_____ section type-parameter
Generics Declaring more than 1 type parameter Create a method that takes two type parameters: public static <T,S> void twoTypeParameter(T key, S value){ ... }
Generics Methods that use a parameter as the Return Type Can a relational operator be used with return types? No
Generics Methods that use a parameter as the Return Type It is possible to compare 2 objects of the same class if that class implements the generic interface _____ Comparable<T>
Generics Methods that use a parameter as the Return Type Example of Comparable
Generic Classes Creating a String variable at the top of the class (e.g. Private String Name;) means that it can only take a _____ as its content String
Generic Classes public class GenericBox <T>{ Generically defining a class (as above) enables a lot more flexibility and also includes _____-_____ saftey Compile-time
Generic Classes Compile-Time Safety At compile time, the compiler ensures the _____ safety of your code and uses erasure techniques to enable a more usable system. type

Semelhante

Who goes first
Karl Taylor
Get player names
Karl Taylor
alfabetização e letramento- Pedagogia
Karina Priscila
CAv - controle de avarias
willian reis
Níveis de organização dos seres vivos
GoConqr suporte .
Direito Civil
GoConqr suporte .
História da Arte - Barroco
Bruno Torrezan
Geografia do Brasil
JOISSE DE OLIVEIRA
EMILE DURKHEIM
Débora C. Nascimento
SEGUNDO REINADO
Lucas Villar