Can we call a method by inferring a type ?

Hi,
Pardon my ignorance. Why doesn't type inference help in writing code like this ?
<code>
public class TypeInferredMethodCall {
private interface Base {
     public void x();
private static class Derived implements Base {
     public void x(){
static <T> List<T> getList(Class<? extends T> type) {
     // T.x(); -> Error
return new ArrayList<T>();
public static void main(String[] args) {
List<Base> list2 = getList( Base.class );
</code>
Thanks,
Mohan

Do you mean that you can't write T.x()? That is completely normal: you couldn't write Derived.x() either. More importantly, here T is being erased to Object, so you couldn't do this either:
static <T> List<T> getList(Class<? extends T> type,T obj) {
    T.x()
}for that to work you would have to do this:
static <T extends Base> List<T> getList(Class<? extends T> type,T obj) {
    T.x()
}

Similar Messages

  • Can we call a method in stateless session bean ?

    Can we call a method in stateless session bean in onMessage method?

    Hi,
    The purpose of service locator is to abstract the lookup of the server side services like ejb and DSNs. It should be a normal java class but as such there is no such restriction. You can have a look at the service locator patter at the j2ee blue prints.
    /Ashwani

  • Can we call a method from a adapter class?

    Hi
    I have added KeyAdapter class to a textfield now i want to call a method in the outer class from inside the adapter class. I tried but its showing some error,
    public class A
    A()
    TF1.addKeyListener(new KeyAdapter()
    public void keyReleased(KeyEvent e)
    A a=new A();
    ec.chkSalary();                    
    chkSalary()
    can i call the method like this?

    yeah.. i got it.. i just passed that KeyEvent object to the method
    but i did declare that as a char in that method like,
    chkSalary(e) // e is the KeyEvent reference
    and the method is
    chk(char e);
    thats it.
    thank you yaar.

  • Can we call main method in another class?

    Hi...
    can we call main method in another class?
    If no, please tell me the exact reason why can't we call that....

    ok
    can u give that code for me?
    class A {
    public static void main(String [] args){
    System.out.println("In A");
    class B {
    public static void main(String [] args){
    A.main(null);
    }

  • How can I call a Method in a Transformation Routine

    Hello Experts,
    How can I call a Method in a Transformation Routine ??
    THNXX

    Hi,
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/6090a621-c170-2910-c1ab-d9203321ee19?quicklink=index&overridelayout=true
    It will be help full .
    Regards,

  • How can we call the method of used controller?

    Hi All,
       i created two WDA Applications.( like YWDA1,YWDA2 ) . i am using the component WDA2 in WDA 1.and displaying the one view of WDA2 as popup window in WDA1 on action of one of the input element in the view of WDA1 by using the method l_window_manager->create_window_for_cmp_usage
    I have a button on the view of WDA2 which has appear in the popup window...how can i call the method which has binded to that button....and where should i code that...and i need to assign selected value in the popup window to input elemetn of view  WDA1
    Please help me to resolve this....
    Regards,
    Ravi

    You can not directly call view's event handler from other component.
    create a method in component controller of the second component and in the button click call the component controller method. ( also make the method as interface so that you can call it from other components )
    Now, you can call the interfacecontroller's method
    DATA: l_ref_INTERFACECONTROLLER TYPE REF TO ZIWCI__VSTX_REBATE_REQ_WD .
      l_ref_INTERFACECONTROLLER =   wd_This->wd_CpIfc_<comp usage name>( ).
      l_ref_INTERFACECONTROLLER->Save_Rr(
        STATUS = '01'                       " Zvstxrrstatus
    save_rr is the method of second component controller

  • How can I call a method for all instances of a certain class?

    Hi,
    I have created a snake java applet, which you can play here [http://users.telenet.be/javagames/|http://users.telenet.be/javagames/].
    But now I want to make this into a multi-player game (with two or more snakes etc..).
    In my main class you can find methods like these:
    snake.move();
    snake.drawSnake();Now if I just alter my main class and make a second instance of the class snake and change my methods to this,
    snake.move();
    snake2.move();
    snake.drawSnake();
    snake2.drawSnake();my game almost works perfectly, I'll have to make some minor changes though.
    But my question is, is there a better way of doing this. Instead of duplicating all the code, how can I make the methods immediately work for both snakes, instead of calling it twice?
    All suggestions are welcome!
    Thanks in advance.
    Lennart

    If there was something common to all snake instances then you could declare that variable static.
    Note: I don't want to confuse you here. A static variable can have a value apart from any instances at all. Instances can view static variables but a static method or inner class, for example, cannot view instance variables.
    More generally, I would think you would want to treat each snake as an automaton with its own behavior. There must be some class such as Game or Board or whatever that has, as suggested, either an array or collection of snakes. Iterate over each snake, ask it to perform some computation for the game and then draw itself.
    - Saish

  • Can we call DLL method in jave code

    hi,
    can we call DLL file method in java Code or program.

    See
    http://forum.java.sun.com/thread.jsp?forum=52&thread=179765

  • How Can I Call a method in iView  ,which is in another iView

    I Have 2 iViews i want to call a method in Iview which is i another iView
    Thanks and Regards
    Prasad.Y

    Hi Prasad,
    first, welcom at SDN.
    Next, let us clarify some wording:
    A <i>PAR</i> is a <i>Portal ARchive</i>. It is a zip in a certain format. It contains a <i>portal application</i>.
    A <i>portal application</i> consists of <i>components</i> and/or <i>services</i>.
    An <i>iView</i> is somehow an "instance" of a <i>component</i>. It is created within the portal. There are <i>no iViews in a PAR</i> (like: "There are no objects in a JAR (but classes).").
    With this in mind, you know that the question does not work, for iViews don't have "methods".
    If you ask how you can call a method of a class belonging to a different component (but within the same portal app), it is no problem at all, each class has access to each other class within the same portal app (in fact, one has to differentiate between public and private part, but we don't want to go so far). To call use a class belonging to (the public part of) a different app, you will have to set the SharingReference within portalapp.xml.
    If that's what you're looking for - great.
    If not, ask again, but far more detailed.
    Hope it helps
    Detlev
    PS: Please consider to reward points for helpful answers. Thanks in advance.

  • Add a column and I can't call a method

    I'm trying to make a small portal app with IBM RAD 6.0 but I'm having a wierd problem calling a method in my page code. Any help would be great.
    Here's the cod I'm using, I've got a bunch of system.outs in it to help me track down what's happening as well as some commented code of some things I'm trying. Any why here goes:
    I start a data table in the jsp like this
    <h:dataTable value="#{pc_MaintainBasisFormView.memberBasisComponents}" var="results"
                             border="0" cellpadding="2" cellspacing="0"
                             columnClasses="columnClass1" headerClass="headerClass"
                             footerClass="footerClass" rowClasses="rowClass1"
                             styleClass="dataTable" id="table1">
    later I build these two columns
    <h:column id="startdatecolumn">
                                  <f:facet name="header">
                                       <h:outputText styleClass="outputText" value="Start Date" id="startdateheader" />
                                  </f:facet>
                                  <h:inputText styleClass="inputText" id="startdate" value="#{results.effectiveDates.effectiveStartDate}"></h:inputText>
                             </h:column>
                             <h:column id="column7">
                                  <f:facet name="header">
                                       <h:outputText styleClass="outputText" value="Remove" id="remove"></h:outputText>
                                  </f:facet>
                                  <h:commandLink styleClass="commandLink" id="removelink" action="#{pc_MaintainBasisFormView.removeBasisComponent}">
                                  <h:outputText id="text6" styleClass="outputText" value=">>"></h:outputText>
                                       <f:param name="krusty" value="#{results.id}"></f:param>
                                  </h:commandLink>
                             </h:column>
    so column startdate calls does this "results.effectiveDates.effectiveStartDate"
    so results has this method
    public EffectiveDates getEffectiveDates() {
              System.out.println("in getEffectiveDates " + effectiveDates);
              //effectiveDates = (effectiveDates == null) ? new EffectiveDates():effectiveDates;
              return effectiveDates;
    and EffectiveDates has this method
    public String getEffectiveStartDate() {
              System.out.println("in getEffectiveStartDate " + effectiveStartDate);
              effectiveStartDate = (effectiveStartDate == null) ? new Date() :effectiveStartDate;
              return "dfgdfG";
    (it's supposed to return a date but I've set it to a string just to try to get it working)
    and that all works fine.
    Now the second column calls "pc_MaintainBasisFormView.removeBasisComponent" with a parameter <f:param name="krusty" value="#{results.id}">
    and removeBasisComponent is defined as
         public String removeBasisComponent() {
              System.out.println("in removeBasisComponent");
              String id = getPortletRequest().getParameter("krusty");
              System.out.println("in krusty " + id);
              return "removeBasisComponent";
    so whats the probelm? When I click the link in the second column, the method that it is tied to is never called. BUT, when I don't have the first column, the link works as I expect it to.
    can anyone point me in the right direction to solve this problem?
    Thanks in advance
    JohnL

    Hi Ruhi
    I hope this answer doesn't come too late, for some reason the forum does not let me in w/ my username & password, and won't allow me to follow the "Forgot password" procedures.
    Anyway:
    I don't have the code but I'll try to explain the problem using the info I posted originally.
    my problems start here:
    <h:inputText styleClass="inputText" id="startdate" value="#{results.effectiveDates.effectiveStartDate}"></h:inputText>
    It generates an input box with the value results.effectiveDates.effectiveStartDate. What I didn't know was that when I tried to submit the form from the link the application was silently failing. By silently I mean there was no error in the log, nothing, not a clue as to what the problem was.
    The problem turned out to be pretty simple. When the form is generated with results.effectiveDates.effectiveStartDate
    it was essentially running results.getEffectiveDates().getEffectiveStartDate() which, from my example, returned a string. That's great, no problem.
    When the form is submitted it was trying to call results.getEffectiveDates().setEffectiveStartDate(), where the method setEffectiveStartDate must take a String argument, setEffectiveStartDate(String EffectiveDate). Remember that in my example I was returning a string to the from...so I needed to accept a string as an argument to the set method.
    I hope this helps.

  • Why can't call java method when I input  4 bytes character to the TextInput

    I am using Flex4 + Cairngorm2 + BlazeDS3.2 + Java + Spring
    Can't call java program when I input  4 bytes character in Flex.
    Example:
    Please help!

    Basic troubleshooting steps clearly outlined in the User Guide are restart, reset, restore from backup, restore as new device.
    Have you tried ALL the troubleshooting steps?  If you have and you're still having problems, then you'll need to bring your phone into Apple for evaluation and possible exchange.

  • Call a method with complex data type from a DLL file

    Hi,
    I have a win32 API with a dll file, and I am trying to call some methods from it in the labview. To do this, I used the import library wizard, and everything is working as expected. The only problem which I have is with a method with complex data type as return type (a vector). According to this link, import library wizard can not import methods with complex data type.
    The name of this method is this:   const std::vector< BlackfinInterfaces::Count > Counts ()
    where Count is a structure defined as below:
    struct Count
       Count() : countTime(0) {}
       std::vector<unsigned long> countLines;
       time_t countTime;
    It seems that I should manually use the Call Library Function Node. How can I configure parameters for the above method?

    You cannot configure Call Library Function Node to call this function.  LabVIEW has no way to pass a C++ class such as vector to a DLL.

  • How can I call a method of an object that is stored in an ArrayList?

    Hello,
    I am working on a simple game.
    I have my own collection class that can contain some Brick objects.
    That class looks like this:
    class MyCollection<Brick>
          ArrayList<Brick> list = new ArrayList<Brick>();
          public void add(Brick obj)
                list.add(obj);
         public int get(int i)
                return list.get(i);
         public int length()
               return list.size();
    }My Brick class is abstract and contains this method:
    public abstract int getXpos();That method is overridden by the subclass Brick_type1 (which, of course, extends Brick) and returns an int.
    In my main class I try to call the getXpos() method but I cannot call if for an unknown reason:
    MyCollection mc = new MyCollection<Brick>();
    Brick_type1 bt = new Brick_type1(10);
    mc.add(bt);
    for(int i = 0; i<mc.length(); i++)
                System.out.println(bc.get(i).getXpos());   // getXpos() does not exist, says the compilatorbc.get(i) should return a Brick that contains the getXpos() method, so why can´t I call it?

    Roxxor wrote:
    Sorry, it should be:
    public Brick get(int i)
    return list.get(i);
    }...so it actually returns a Brick, but I still cannot call the getXpos() method for some reason.Is this also just a typo?
    MyCollection mc = new MyCollection<Brick>();

  • How Can I Call the method in WAR project's class?

    Message was edited by: JUNHA SHIN

    I have one correct Web Moudule Project.
    The EAR project(EmployeeCardJdoEar) added the WAR archive
    (EmployeeCardJdoWar) is run correctly.
    I want to add the war archive to my WD project.
    because, the war project contain business logic to be reused.
    so. i had enrolled in my WD project's properties ->
    Web Dynpro References -> Sharing References ->
    sap.com/EmployeeCardJdoEar.
    but, this method in WAR(EmployeeCardJdoWar) occurs Exception.
    Context ctx = new InitialContext();
    pmf = (PersistenceManagerFactory)
               ctx.lookup("java:comp/env/jdo/defaultPMF");
    I think lookup call is not run correctly.
    But, this lookup is run correctly in my EAR project.

  • Can we call a method before and after Export operations in ADF 11g

    Hi,
    My problem is I have to execute a method before and after the export operation.Is this posible in ADF 11g
    Regards,
    Felix

    Hi,
    in response to a similatr post of yours, I replied
    1. Drop af:exportCollectionActionListener on a command button
    2. set the command button to display = false
    3. In your Java code, call
    ActionEvent ae = new ActionEvent(button);
    ae.queue();
    Everything you put before
    ActionEvent ae = new ActionEvent(button);
    ae.queue();
    will fires as a pre-trigger, everything after as a post trigger
    Frank

Maybe you are looking for

  • HT1420 How to remove credit card for iTunes

    Yes I have been trying to remove my credit card.  I put 50 iTunes.  But will not quit going to prepaid credit.  No funds. 

  • Add data item from a table to another table

    I have two tables,  "Model" and "Colour". Fields of Model are "Id", "ModelId" and "ModelName" and fields of Colour are "Id", "ColourId" and "ColourName". These two tables have one to many relationship. A model must have a colour. One Colour can have

  • Launhing browser from java

    Hi I'm Launching jsp from my java code with the help of Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + strUrl); when this jsp is Launched it passes the parameters to another jsp with action property of form.and the new browser is

  • Submit a PNP Report with A Radiobutton Parameter

    Hi, i have a fm to submit a PNP report, i sent selection options parameters but radiobutton parameter wasn't sent. FUNCTION ZHR_SUBMIT_TO_ZHRSABORDROWDA.      submit ZHRSABORDROWDA             WITH wdaflag  = 1             WITH pnppernr in personel  

  • Group by and concat one column

    Hello, i have a query that gives me the following results (example): Column1 Column2 Madrid Product1 Madrid Product2 Madrid Product3 And my problem is that i want to have just one record with a group by for column1 and a concatenation of column2 like