What is the use of Generic class in java

hi everyone,
i want to know that
what is the use of Generic class in java ?
regards,
dhruvang

Simplistically...
A method is a block of code that makes some Objects in the block of code abstract (those abstract Objects are the parameters of the method). This allows us to reuse the method passing in different Objects (arguments) each time.
In a similar way, Generics allows us to take a Class and make some of the types in the class abstract. (These types are the type parameters of the class). This allows us to reuse the class, passing in different types each time we use it.
We write type parameters (when we declare) and type arguments (when we use) inside < >.
For example the List class has a Type Parameter which makes the type of the things in the list become abstract.
A List<String> is a list of Strings, it has a method "void add(String)" and a method "String get(int)".
A List<File> is a list of Files, it has a method "void add(File)" and a method "File get(int)".
List is just one class (interface actually but don't worry about that), but we can specify different type arguments which means the methods use this abstract type rather than a fixed concrete type in their declarations.
Why?
You spend a little more effort describing your types (List<String> instead of just List), and as a benefit, you, and anyone else who reads your code, and the compiler (which also reads your code) know more accurately the types of things. Because more detail is known, the compiler is able to tell you when you screw up (as opposed to finding out at runtime). And people understand your code better.
Once you get used to them, its a bit like the difference between black and white TV, and colour TV. When you see code that doesn't specify the type parameters, you just get the feeling that you are missing out on something. When I see an API with List as a return type or argument type, I think "List of what?". When I see List<String>, I know much more about that parameter or return type.
Bruce

Similar Messages

  • Why class builder allows to develop abstract final class ? What is the use of such class in ABAP?

    I am new to ABAP. I tried creating abstract class and found that class builder allows development of abstract final class. What is the use of such class in ABAP?

    Hi,
    Does not compile:
    This one do:
    Inheritance:
    Regards.

  • What is the use of valuation class in Finished Material Master?

    Dear Expert
    What is the use of valuation class in Finished Material Master?
    Thanks of Advance

    hi,
    this is to inform you that,
    generally 7920 - will be the valuation class for the finished goods.
    Allows the stock values of materials of the same material type to be posted to different G/L accounts & vice versa.
    this is an integration field which identifies the G/L accounts & goods movement types.
    balajia

  • What is the use of Inner class.?

    hello everyone.........
    I want toknow that what is the use of Inner class...?

    Judging from what's seen around here? Mainly obfuscation.

  • What is the use of CVI_BDT_ADAPTER class ?

    Hi Freinds,
    what is the use of CVI_BDT_ADAPTER class ? can any one explain ?
    thnx n regards
    Vijaya

    Hi,
    This class is used for following cases:
    1.modify fields depending on customer status
    2.modify fields depending on vendor status
    3.to check user has the authorization
    to view/change/create data in the specified sales area

  • What is the use of Serializable Interface in java?

    Hello friends,
    I have one dout and i want to share with u guys:
    Why Serializable interface made and actully
    what's the use of it?
    At which place it become useful ?
    It is not contain any method then why it is made?
    If anyone have any idea about this then please reply.
    Thanks in advace
    Regards,
    Jitendra Parekh

    t is not contain any method then why it is made?To point out to the user of a class (and the programs) that the design of this class is conforming to certain restraints needed for Serialization.

  • What is the Use of Inner classes in Interface.

    Hi All,
    Most of us we know that We can define inner classes in the interface. Like
    public interface MyItf{
         Demo d = new Demo();     
         class Demo{
              Demo(){
              //some additional code here
    }Now I have following question in my mind:
    1. An Interface is pure abstract. Then why inner classes inside the interface?
    2. In what scenario, we can utilize these inner classes of interface?
    Plz Share your views on this...
    Thks for ur replies in advance.

    This we cando in defining Demo Class outside.That's no argument. You could write the programs in other languages, so why use Java? Just because you can use a top-level class instead, it's no argument against using an inner class. You also can make all attributes public... you don't o that either (I hope).
    Ok Also
    tell me how to pass an Object in inner class Demo. to
    the method of Interface.
    public abstract TheInterface.Demo doSomething(TheInterface.Demo d);
    Can u give some real time situation where this
    concept can be used.There are only very, very few. Just because it's possible, it doesn't mean it needs to be done or is done often.

  • What is the use of feeder class ? & can we create feeder class ?

    i have the fpm developer guide , more detail of feeder class ?

    Dear Madhukar.
    Your can see class assinment for feeder in transaction POWL_TYPE.
    Of course, you can create feeder class by yourself and assign it to feeder.
    Your should to imlement IF_POWL_FEEDER interface in your class.
    The best way for feeder class creation is to find fider with close behavior in transaction POWL_TYPE and make copy.
    For FPM applications there is the separate forum in sdn called Floorplan Manager for WebDynpro Abap,
    your should post your question there/.

  • What is the Use of Abstraction

    What is the Use of Abstract class..
    Edited by: Deenu on Jul 1, 2008 11:11 PM

    Deenu wrote:
    What is the Use of Abstract class..It's highly effective in confounding lazy noobs.
    Instead of posting every question that pops into your mind and waiting for somebody to spoonfeed you the answer, you might find it useful to go through one or more tutorials or texts on Java. For instane, perhaps one or more of the following might be useful.
    Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
    Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    [http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
    Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
    Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
    James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806]. Gosling is
    the creator of Java. It doesn't get much more authoratative than this.

  • What are the uses of Void wrapper class?

    Hi,
    Similar to other Wrappers, Void is a wrapper class for the primitive ' void ' . We all know that Void is a final class , we can't instantiate it.
    My Question is what are the uses of Void?
    thanks,

    kajbj wrote:
    I have at times used it in reflection and jmx.I have used them with SwingWorker if I didn't have anything interesting to return. There is also an example in the tutorial: [http://java.sun.com/docs/books/tutorial/uiswing/concurrency/simple.html]

  • What is the use of class Class

    What is the use of class Class?

    Sample use: if you are specifying the name of a class in a config file, you can use Class method newInstance to instantiate it.:
    String classname = ...
    Runnable r = (Runnable) Class.forName(classname).newInstance();
    r.run();

  • What are the major components in class?

    1)     What is the purpose of ‘load-of-program’? When it will be trigger?
    2)     Write the code for displaying the three parameters in single line with the first parameter as mandatory in the selection screen?
    3)     Which event triggered whenever the user call the function BACK, EXIT, CANCEL?
    4)     What are the major components in class?
    5)     What is the functional module is used to get popup screen for ALV reports?
    6)     Which type of pool is used to get drop-down list?
    7)     What is the tcode for creating the variant truncations?
    8)     Is it possible to call LDB’s number of times in same report?
    9)     What are the conditions to use control break statements in our report program?
    10)     What is the use of range statement?
    11)     What is the difference between normal reports and alv reports? With comparing to normal report are there any disadvantages in alv reports?
    12)     What are the components used to suppress the fields in the selection-screen?
    13)     What is the standard program to transport selection screen variants?
    14)     What is the event keyword for defining event block for reporting events?
    15)     What is the specific statement use when writing a drill down report?
    16)     What are the different tools to report data in sap?
    17)     Write the menu path to create a selection text in reports?
    18)     How do we omit the leading zero s while formatting outputs in reports?
    19)     What are the report truncations?
    20)     How do we align selection input in single row?
    21)     How do we suppress the display of input fields on selection screen?

    this forum is not for answering your interview questions...if you stucked with any realtime problem then post...please try to respect forum terms and conditions.
    Thank you.

  • What is the use of access level

    Hi Experts,
    What is the access level and what is use of each option in access level
    1  Application
    2  Superior component
    3. Top Component
    4. Sap
    5. Global
    and in Details section what is the use Properties tab
    1. Application Component
    2. Software Component
    3. Development Package
    4. Settings Class
    Please explain Each option use.
    Thank you in advance,
    Srini M.

    Hi Srini,
    just read the documentation (although the current status on SAP Help Portal isn't really up-to-date):
    1. [Entry point|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/cc/85414842c8470bb19b53038c4b5259/frameset.htm]
    2. [Setting an Access Level|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/32/6aba9c49fd41a5a14f710e121220f1/content.htm]
    W/r to "Application Component" etc., docu on Help Portal is definitely not sufficient. Here, the following applies:
    An application offers attributes for the application component and the software component. The application component and software component have to be the same as defined for the development package. Application and software component are automatically derived from the development package if they are not set explicitly.
    For the definition of the development package, application component, and software component, we recommend that you choose the same values that are in effect for the software solution that you want to enhance by a new BRFplus application. This simplifies all activities related to the software infrastructure, especially transports.
    CU
    Claus

  • What is the use of delta in BW side when we have delta in R/3

    Hi,
    what is the use of delta in BW side when we are already using delta in R/3 side?
    Like,
    Generic extraction:-
    with different delta extractions (Time stamp, Calendar day, Numeric pointer).
    Lo-Cockpit extraction with change log method.
    Co/Pa extraction with time stamp method.
    So from this delta activation first time full data will be loaded and after that only changed data will be loaded because of these deltas in R/3 side.
    So now my question is what is the exact use of delta in BW side with ODS/DSO because data already reached to BW with delta activation right.
    Can you please explain me what is the exact use of BW delta?
    Thanks in advance.
    Points to be added.
    Regards,
    Shyam.

    The purpose of Delta Queue is same in R/3 and BW.
    In BW, Delta Queue is used to capture changes made to objects within BW. (for Eg: BW Statastics)or Update data from one BW system to another BW system (if you have multiple BW systems).
    Message was edited by:
            Praveen Vujjini

  • What is the use of XML file in EJB

    Hi,
    Generally EJB contains
    1) Home Interface
    2) Remote Interface
    3) Bean class
    4) XMl file
    In xml file we will mention something like
    <home>name of home interface </home>
    <remote?name of remote interface</remote>
    what is the use of this xml file and how it works.
    Thanks.

    It's called the deployment descriptor and it's used by the container to support your bean's configuration. For instance, if you want container managed persistence for an entity bean then you need to tell the container which table to use in which database with the column mappings, etc.

Maybe you are looking for

  • Is there a fix for Mountain Lion audio output settings after the laptop goes to sleep and wakes back up?

    Mac Book Pro running Mountain Lion OS X 10.8.5 after the notebook sleeps audio and video does work (for example on YouTube).  I have been able to temporarily work around this by toggling the settings on Built-in Output in Audio Midi Setup, Audio wind

  • Workflow to move documents to Record Centre

    Hi, I'm developing a Approval workflow to move documents to a  Record Centre Site on approval. The workflow works fine until I add the If to test if the workflow outcome for the move/archiving of the document was Approved or Rejected. The issue seem

  • Pass parameter to ssrs report in performance point webpart from textbox text

    How to pass parameter to ssrs report  in performance point webpart from textbox text Please help me to solve this ... Bikky Kumar

  • Table controls

    hi friends i created a table control .but its giving syntax error like this . The field "AGE" is not assigned to a loop. "LOOP ... ENDLOOP" must appear in "PBO" and "PAI".           please help me. please look at this code . tables : zpr_table. data

  • Job Scheduling on Oracle 10g RAC

    Hi, If I want to run job on Oracle 10g RAC database having 2 instances suppose n1 and n2 separately and both instances are working/using same Service Name then how could i do this ?? or how to use SID instead of Service Name in Job Class ??? Please g