Generic Classes and Methods

Description

Masters of Science Programming 2 Flashcards on Generic Classes and Methods, created by Nathan Hunsdale on 01/06/2014.
Nathan Hunsdale
Flashcards by Nathan Hunsdale, updated more than 1 year ago
Nathan Hunsdale
Created by Nathan Hunsdale almost 10 years ago
86
0

Resource summary

Question Answer
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
Show full summary Hide full summary

Similar

Who goes first
Karl Taylor
Get player names
Karl Taylor
C1 - Formulae to learn
Tech Wilkinson
AS Psychology - Research Methods
kirstygribbin
Food Vocabulary Quiz
Liz Bartik
USA and Vietnam (1964 - 1975) Part 2
Lewis Appleton-Jones
Summary of AS Psychology Unit 1 Memory
Asterisked
OCR AS CHEMISTRY A DEFINITIONS
awesome.lois
Biology B1
themomentisover
The Nervous System and Hormones (Part 1)
Naomi Science
IB ITGS AREAS OF IMPACT
san wis