What’s the difference between the word “Abstract” and “Generic” code in case of Java? Are both mean the same?
What’s the difference between the word Abstract and Generic code in case of Java?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Abstract and Generics are completely different things in Java syntax and semantics.
abstract is a keyword, and indicates that a class does not contain a complete implementation, so cannot be instantiated.
Example:
MyClass contains a method definition ‘public abstract void myMethod()’, but does not specify an implementation – an implementation must be provided by a subclass, usually referred to as a concrete subclass, so an abstract class defines an interface, perhaps with some implementation detail.
The use of generics indicates that aspects of a class can be parameterized. I find the easiest to understand example is in the Java Collections API.
For example
List<String>can be read as ‘List of objects of type String’.List<Integer>is the same List interface, but only accepts objects of type Integer.In the Collections API, it provides type-safety for collections that otherwise require boilerplate to check types and cast appropriately.