Regarding Generics classes

I have confusion with below code...
which of them are valid inserts?
class Parent<E>
public E get() { return null;}
public void set(E e) { }
class Child extends Parent<Number>
//insert here
options given to insert are
a public Object get() { ... }
b public Long get() { ... }
c public void set(Object arg) { ... }
d public void set(Long arg) { ... }
e public Number get() { ... }
and ans is b,d,e.Iam fine with it.
But i have confusion with option c.Why "option c" is wrong?In option c,
we hava "Object arg" as argument, so isn't it a valid overloading example?
see here their is a statement in above code "class child extends Parent<Number> ".
Therefore
set(E e) of Parent class should be "set(Number e), "
and in child class if we have option c, which is set(Object e), then what is wrong in it?Wont it be a vaild overloading example

I have confusion with below code...
which of them are valid inserts?
class Parent<E>
public E get() { return null;}
public void set(E e) { }
class Child extends Parent<Number>
//insert here
options given to insert are
a public Object get() { ... }
b public Long get() { ... }
c public void set(Object arg) { ... }
d public void set(Long arg) { ... }
e public Number get() { ... }
and ans is b,d,e.Iam fine with it.
But i have confusion with option c.Why "option c" is wrong?In option c,
we hava "Object arg" as argument, so isn't it a valid overloading example?
see here their is a statement in above code "class child extends Parent<Number> ".
Therefore
set(E e) of Parent class should be "set(Number e), "
and in child class if we have option c, which is set(Object e), then what is wrong in it?Wont it be a vaild overloading example

Similar Messages

  • 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

  • XI: How To Use JAVA generic Class to  perform SAP data Lookup........

    Hello All,
    I want to create a generic class which is used to perorm SAP data lookup.
    I don't want to use Jco or RFC channel..
    Is there any other way to do this?
    waiting for Reply 
    thank in advance.
    - AKSHAY.

    Hi,
    use RFC channel
    you can wrap it up like this:
    /people/morten.wittrock/blog/2006/03/30/wrapping-your-mapping-lookup-api-code-in-easy-to-use-java-classes
    why do you want to create something diffucult to maintin and non standard if
    you can use the RFC API ?
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

  • Generic CLASS parameters

    Hi,
    I have a function module with a  TABLE  parameter with generic type TABLE.
    I have to pass these table parameter to a method in the class, then what should be the type of the corresponding parameter inside my class.
    Regards,
    Anoop

    Ah, you can't create a generic class attribute.  But you <b>can</b> create a data reference to a generic object.
    Instead of creating an attribute "mytab", create an attribute that is a reference to data,e.g. <b>ref_mytab</b>, of type REF TO DATA.
    In your method, where you've received the table through the parameters (e.g. it_mytab TYPE STANDARD TABLE ), do this:
    GET REFERENCE OF it_mytab INTO ref_mytab.
    Whenever you need to do something with the table, do this:
    FIELD-SYMBOLS: <mytab> TYPE STANDARD TABLE.
    ASSIGN ref_mytab->* TO <mytab>.
    matt

  • Using static .values() method of Enum in Generic Class

    Hi *,
    I tried to do the following:
    public class AClass<E extends Enum<E> >  {
         public AClass() {
              E[] values = E.values(); // this DOESN'T work
              for (E e : values) { /* do something */ }
    }This is not possible. But how can I access all Enum constants if I use
    an Enum type parameter in a Generic class?
    Thanks for your help ;-) Stephan

    Here's a possible workaround. The generic class isn't adding much in this case; I originally wrote it as a static method that you simply passed the class to:
    public class Test21
      public static enum TestEnum { A, B, C };
      public static class AClass<E extends Enum<E>>
        private Class<E> clazz;
        public AClass(Class<E> _clazz)
        {  clazz = _clazz;  }
        public Class<E> getClazz()
        {  return clazz;  }
        public void printConstants()
          for (E e : clazz.getEnumConstants())
            System.out.println(e.toString());
      public static void main(String[] argv)
        AClass<TestEnum> a = new AClass<TestEnum>(TestEnum.class);
        a.printConstants();
    }

  • Hp LaserJet 1200 Generic Class: Waiting for device

    I have 2 computers that I want to print to my hp Laserjet 1200 printer. We are using an iogear 4-port usb 2.0 sharing switch. One computer prints fine but the other always displays a message "Generic Class: Waiting for device." Help!

    Both computers have the printer driver installed. The usb device does not have a driver to install. You just plug in the usb cords to each computer and the printer. You only install a driver if using a pc operating system.

  • Best way to call a function in a generic class from a base class

    Hi,
    I have a generic class that works with subclasses of some other baseclass. When I construct the subclass, I call the constructor of the baseclass which I want to call a function in the generic class. e.g. suppose I have the following classes
    public class List<T extends BaseClass>
        newTCreated(T t)
    }

    Sorry, I pressed Tab and Enter last time when typing the code so I posted without meaning to
    Hi,
    I have a generic class that works with subclasses of some other baseclass. When I construct the subclass, I call the constructor of the baseclass which I want to call a function in the generic class. e.g. suppose I have the following classes
    public class List<T extends BaseClass>
        public void newTCreated(T t)
            // add the t to some internal list
        public T getT(int index)
            // get the object from the internal list
    public class BaseClass
        public BaseClass(List<?> list)
            list.newTCreated(this);
    public class SubClass extends BaseClass
        public SubClass(List<SubCass> list)
            super(list);
    }This doesn't compile because of the call to newTCreated in the BaseClass constructor because BaseClass is not necessarily of type T. Is there any way of checking when I call the newTCreated function that the BaseClass is actually of type SubClass? I could either add the call explicitly in each SubClass's constructor or have a function addToList in BaseClass that is called from the BaseClass constructor but overloaded in each subclass but both of those rely on future subclasses doing the same. Or I could change the newTCreated function to take an argument of type BaseClass and then cast it to type T but this doesn't give a compilation error, only a runtime exception.
    It seems like there should be solution but having only recently started writing Generic classes I can't find it. Thanks in advance for any help,
    Tom

  • Getting the name of the generic class?

    I have a generic class declared as such:
    public class MyClass<T>
    and I want to access the name of the <T> class a member function in that class? I just can't figure out which syntax to use.
    Thank you!
    Joshua

    Sorry, I'm a little bit confused at your answer.
    I cannot seem to instantiate an object of class T, like: T item = new T();does not work. If I can't create an object of type T, then I can't get it's type. I need to get the class even if I don't have any instantiated objects (or if I can create a blank one), so that I can use the name to fetch the objects from the persistence engine. Here is the class, so you can see what I'm talking about. I have in there now what seems like it should be right, but doesn't compile.
    A small example of solution please?
    public class PersistentSelectorCellEditor<T> extends AbstractCellEditor
              implements TableCellEditor {
         JComboBox control;
         List<T> choices;
         Session session;
         public PersistentSelectorCellEditor() {
              initializeComponents();
         public PersistentSelectorCellEditor(Object value) {
              initializeComponents();
              this.control.setSelectedItem(value);
         private void initializePersistence() {
              session = LabApp.getSession();
              session.beginTransaction();
         private void initializeComponents() {
              initializePersistence();
              populateList();     //query for selections to fill combo box
              control = new JComboBox((ComboBoxModel)choices);
         private void populateList() {
              //query to populate drop down lists
              Query query = session.createQuery("from " + T.class.getName());
              choices = query.list();
         public void setValue(T value) {
              control.setSelectedItem(value);
         public T getValue() {
              return (T)control.getSelectedItem();
         //interface members
         public Object getCellEditorValue() {
              return control.getSelectedItem();
         public Component getTableCellEditorComponent(JTable table, Object value,
                   boolean isSelected, int row, int column) {
              return control;
    }Thank you!
    Joshua

  • Array of generic class

    Hi.
    i have to create an array of generic class
    ex: GenericClass<E> [ ] x = new GenericClass<E>[ y ]
    is it possible?
    i can create GenericClass<E> [ ] x; but i can't initiate it in this way..
    Someone know how i can do it?

    crosspost
    http://forum.java.sun.com/thread.jspa?threadID=746524&messageID=4272614#4272614

  • Regarding Generic Extraction

    Hi Experts,
    I m new to SAP BW, I need a information regarding Generic Extraction as the senario is follows.
    I created a table with fields,
    Customer Id (PK), name, age ***, address
    and i maintained five records in it.
    i created a generic master data attributes data source using above table
    i replicated the data source in bw and run the full update and it is succussful.
    Now my requirement is to add 5 more records in the above table and i hav to get those records in bw using delta update.
    So, can any one can explain how to maintain delta for that generic datasource and how to run delta update in step-by-step process
    regards,
    Ramakrishna

    Check the PDF doc..on how to create generic delta..
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/84bf4d68-0601-0010-13b5-b062adbb3e33
    Check this doc for more
    http://www.ko-india.com/content/weblogs/generic_delta_explained.pdf
    Regards,
    R.Ravi
    Assigning Points is the way of saying Thanks in SDN!

  • Regards Generic Delta

    Hi Guys,
    I have a small doubt regarding Generic Delta Extraction. In Generic Delta i choose Calday on Posting Date. And  am getting data on Daily basis. Here My doubt is can I use this posting date in field selection in Info package. If not?Please give me clarification regarding the same.
    Thanks,
    Tg.

    Hi Tg,
    If I have understood correctly, Posting date has been chosen as the delta field in datasource.
    I don't think you can use the fiield in infopackage selection because the field is used to extract delta for that generic datasource  and the system doesn't allow us to put a filter on the filed which is responsible for delta .
    If system  wud have allowed us to put a selection on that field then correct delta will not be loaded in BI.
    System can not allow us to play with deltas and hence the field is not avaialble for selection .
    Hope it helps,
    Manish Sharma

  • How to get the parameter name of a generic class?

    Is it possible to get the name of generic class parameter type without having an instance of that type?
    e.g.
    class MyClass<T> {
      public MyClass() {
      // get the name here
    }

    I need to get a string containing "Object" (or "java.lang.Object") if the class would be used like this:
    MyClass<Object> mc = new MyClass<Object>()

  • Generic classes with parameterized super class and interface

    Hello.
    I'm trying to write a generic class that looks like the following pseudo-code.
    public interface Interface {
        public Interface getSibling(...);
    public class Klass {...}
    public class MyKlass<T extends Klass, T2 extends Interface>
            extends T implements T2 {
        public T2 getSibling(...) {
            return this;
    }where Interface and Klass each have various extensions.
    I came across this problem, or challenge, while writing classes for testing my EJBs. I tried and failed various attempts.
    Is it possible to write generic classes of this nature in Java?
    If so, please tell me and others who are like me.
    Thanks in advance.

    No. That would not work.
    Beside being forbidden by the compiler, to my understanding, it cannot be done in theory either, as the parameterized types get bound at instantiation time and are not available for static reference, which both extends and implements require.

  • Question about typecast to more generic Class

    I have controls refnum and pages refnum and I want to know which way is better:  
    1) let LabVIEW doing the job
    or 2) use "typecast to more generic Class". 
    In both case the VI works properly. 
    Thanks
    Jean-Marc
    Jean-Marc
    LV2009 and LV2013
    Free PDF Report with iTextSharp
    Solved!
    Go to Solution.
    Attachments:
    Test LV86.zip ‏153 KB

    Thanks for your reply Ben.
    I need the controls refnum in the visible part of the pane (for the translation english to french and french to english ).
    Jean-Marc
    Jean-Marc
    LV2009 and LV2013
    Free PDF Report with iTextSharp
    Attachments:
    Translation LV86.zip ‏235 KB

  • Support for generic classes

    hi,
    i m using creator 2 update 1, it does not support generic classes.
    it says use source 1.5 for generic classes.
    please tell me how to solve this problem
    thank you

    Well, not necessarily true... Most of the latest graphics cards work off of a common core, which is named depending on its maximum tested performance and on how many pipelines passed quality checks.
    Thus a 7300 is fundementally identical to a 7800, except that it uses fewer fragment/vertex pipelines and is clocked lower. This is done either artificially by disabling parts of the GPU, or if when they fail quality control.
    Either way, the drivers are the same, and have been unified for a long time for the entire product line. In fact if you look at the drivers for the card in yoru computer you will see they are more then likely for a different chipset. My MBP claims the drivers are for a X1000, even though the card is a X1600.

Maybe you are looking for

  • Airport kicks out when I connect to TV

    I managed to connect my MBP to my 40" HDTV (Toshiba) using a mini display port to HDMI adapter and cable and then, by selecting "mirror images" I got the desktop to function on the TV. Problem is, when I connect to the TV, my airport wireless (using

  • All the planned and scheduled appointment can display in  calendar view ?

    1.I want to do some functions. For one day all the planned and scheduled appointments  were displayed in the calendar view in backoffice . Whether SAP CRM standard provided this function? If yes, How to do? 2.Could Upper issue be achieved by per org.

  • CF9 Deleted Scheduled Tasks Still running

    I have several scheduled tasks that were deleted via the admin but they are still running.  Don't show up in the admin, but still run. I have tried to programmatically delete them also.  Have looked in neo-cron.xml and they dont exist in there either

  • Is our oracle 9iR2 db is a shared mode or dedicated mode? whats difference?

    Friends, We are using Oracle 9iR2 Database. How can i know our db is a shared Server architecture or a dedicated server architecture? Also, what is the difference between these two? Please tell me in short. Note: I didn't install/create our db. Thank

  • Isql report about state of database

    Hi all I enter to my isql from web and entered there Then I saw my database status as: The database is currently in started state and I can "Shutdown" or "Mount" or "Open" my database But I'm entering to my database installed computer and issue this