Results 1 to 11 of 11

What is Generics in java

This is a discussion on What is Generics in java within the Programming forums, part of the Web Designing & Development category; Describe generics of java....

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    8

    Default What is Generics in java

    Describe generics of java.

  2. #2
    Senior Member
    Join Date
    Jun 2015
    Posts
    940

    Default Re: What is Generics in java

    Generics are a facility of generic programming that were added to theJava programming language in 2004 within J2SE 5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety." This feature specifies the type of objects stored in a Java Collection.

  3. #3
    Senior Member
    Join Date
    Jun 2014
    Location
    United Kingdom
    Posts
    150

    Default Re: What is Generics in java

    In my opinion the java generics programming is introduced in J2SE 5 to deal with the type-safe objects.

  4. #4
    Senior Member
    Join Date
    Jan 2016
    Posts
    145

    Default Re: What is Generics in java

    Generics in java were added to java in 2004.They allow a type or method to operate on objects of various types.
    Advantages of generics in java:

    • Type Safety
    • Type casting is not required
    • Compile type checking

  5. #5
    Senior Member
    Join Date
    Jan 2012
    Posts
    872

    Default Re: What is Generics in java

    A generic type is a generic class or interface that is parameterized over types. The following Box class will be modified to demonstrate the concept.

  6. #6
    Senior Member charlottegracie's Avatar
    Join Date
    Jan 2017
    Posts
    115

    Default Re: What is Generics in java

    Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods, or with a single class declaration, a set of related types, respectively. Generics also provide compile-time type safety that allows programmers to catch invalid types at compile time.

  7. #7
    Senior Member
    Join Date
    Dec 2016
    Posts
    126

    Default Re: What is Generics in java

    Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods, or with a single class declaration, a set of related types, respectively. Generics also provide compile-time type safety that allows programmers to catch invalid types at compile time.

  8. #8
    Senior Member charlottegracie's Avatar
    Join Date
    Jan 2017
    Posts
    115

    Default Re: What is Generics in java

    The Java Generics programming is introduced in J2SE 5 to deal with type-safe objects.Before generics, we can store any type of objects in collection i.e. non-generic. Now generics, forces the java programmer to store specific type of objects.
    Advantages of generics in java:


    • Type Safety
    • Type casting is not required
    • Compile type checking

  9. #9
    Junior Member
    Join Date
    Jun 2016
    Posts
    24

    Default Re: What is Generics in java

    The Java Generics programming is introduced in J2SE 5 to deal with type-safe objects. It is widely used today.

  10. #10
    Member
    Join Date
    Jun 2017
    Location
    INDIA
    Posts
    72

    Default Re: What is Generics in java

    Generic in Java provides with the storage of similar type of objects in one single collection. objects need not to be type cast here. It is type safe and compiles the objects for checking.

  11. #11
    Senior Member
    Join Date
    Dec 2016
    Posts
    126

    Default Re: What is Generics in java

    The difference is that the inputs to formal parameters are values, while the inputs to type parameters are types. Code that uses generics has many benefits over non-generic code: Stronger type checks at compile time. ... Fixing compile-time errors is easier than fixing runtime errors, which can be difficult to find.