Function overloading concepts

I am a little doubtful about the output of the following code:
public class Test {
     void c(Object a){}
     void c(Float a){}
     void c(Number a){}
     void m(){
          c(null);
     public static void main(String[] args) {
          Test t = new Test();
          t.m();
I an not able to find out the reason why the Float version of the c() will be called?

DeltaGeek wrote:
Hendawy wrote:
The reason behind this is that a null value is a void reference to, i.e. a pointer to nothing. Since it is a pointer (address), it is actually a number. That's why the float version is best matching in your code.Wow...just....not even close.
When determining what method to call, the compiler will find the most specific method it can that matches the arguments you pass in. Since you're passing in an uncast null, it can match any reference type.
In this case, Float happens to be the most specific reference type it could use. This is also why adding an overload for Integer will cause a compilation error, as you now have multiple methods with the maximum level of specificity.
Also note that casting the null to one of Float or Integer would resolve the compile error but hide the design problem.But i have a doubt; if i follow your approach then this code must work:
public class Test {
     void c(Object a){}
     void c(Float a){}
     void c(Number a){}
     void c(DerivedInteger a){}
     void m(){
          c(null);
     public static void main(String[] args) {
          Test t = new Test();
          t.m();
class MyInteger extends Number{
     public double doubleValue() {
          return 0;
     public float floatValue() {
          return 0;
     public int intValue() {
          return 0;
     public long longValue() {
          return 0;
class DerivedInteger extends MyInteger{
because U is the most specific one,

Similar Messages

  • Function Overloading concept in PL/SQL

    hi all,
    do we have Function Overloading concept in PL/SQL? If so, how to implement it? can anybody help me out with an example?

    Yep.
    SQL> create or replace
      2  package test_package as
      3
      4     function blah(param IN NUMBER) return number;
      5     function blah(param IN DATE) return number;
      6     function blah(param IN VARCHAR2) return number;
      7
      8     -- or
      9
    10     function blah(param IN NUMBER) return date;
    11     function blah(param IN NUMBER) return varchar2;
    12     function blah(param IN NUMBER) return char;
    13
    14  end test_package;
    15  /
    Package created.

  • Will ellipsis contradict function overloading

    Recently I was reading the Oracle tech magazin. There was an article in it about the next java major release ( J2SE 1.5 tiger). It said the tiger release will support the ellipsis ("...") concept for parameter passing. I have seen this in C/C++ for passing variable number of arguments in functions like printf() or scanf(). I am not sure has there such a concept already in java but if we are going to have such a mechanism, wont that affect the function overloading concept? Please post ur opinions
    thanks
    boolee

    The method will have a signature ending in (I think the current spec says) Object[], so it shouldn't affect the method overloading much.

  • Function Overloading in PL/SQL

    Hi Guyz,
    I have 2 questions regarding function overloading.
    1) Is it necessary for the functions to be inside a package to perform function overloading ?
    2) I have 2 functions :-
    a) function check_hello( P_INPUT1 VARCHAR2, P_INPUT2 NUMBER) RETURN BOOLEAN
    b) function check_hello( P_INPUT1 VARCHAR2, P_INPUT2 NUMBER) RETURN VARCHAR2
    The difference is the return type . I dont think this is possible since the signature of the arguments are the same. I just need to confirm that its not possible.
    Thanks.

    Hi,
    user3913664 wrote:
    Hi Guyz,
    I have 2 questions regarding function overloading.
    1) Is it necessary for the functions to be inside a package to perform function overloading ?Yes; stand-alone functions cannot be overloaded.
    2) I have 2 functions :-
    a) function check_hello( P_INPUT1 VARCHAR2, P_INPUT2 NUMBER) RETURN BOOLEAN
    b) function check_hello( P_INPUT1 VARCHAR2, P_INPUT2 NUMBER) RETURN VARCHAR2
    The difference is the return type . I dont think this is possible since the signature of the arguments are the same. I just need to confirm that its not possible.Exactly. How could you, the system, or anyone else determine which one to use?
    Give them different names, or add another argument if you really want them to have the same name.

  • Function overloading in flex?

    Hi
    Is it possible to function overloading in flex?
    Any send me example.
    Regards
    D.Mahesh Babu

    ActionScript aims to follow the EcmaScript 4 language specification which does not include method overloading. The two have diverged somewhat because EcmaScript 4 is still in a proposal stage and is subject to change. Read more here:
    http://en.wikipedia.org/wiki/ECMAScript
    A proposed EcmaScript feature called generic functions may offer capabilties similar to method overloading. It is possible such a feature may find its way into ActionScript 4, but I'm not aware of any official announcements to that effect.

  • Regarding Function Module concept

    Hi All,
    Is the Function Module concept meant only for modularity or something to do with the performace also. Please clarify this.
    Thank you
    Satya Priya

    Hi Satya,
                 Function Modules  is used for modularity & performance both.
    In case you dont have a standard extractor suiting to your needs....you need to do complex selects(involves several tables based on your requirement rather than just a table or view selection) , transform your data(manpuliate your data..)....and pass it through data packets..
                          If the join condition is not possible in the view .then we go with Function module.
                 The function module must meet the requirements of a specific interface. The system checks both in Customizing as well as when you use a method in layout, whether the function module is active in the system and whether it meets the requirements of the interface.
    Reward points if helpful.
    Regards,
    Hemant.

  • Doubt in Overloading Concept in Packages

    Hi,
    I have two Stored Procedures are inside a package
    sp_mem(mCursor REFCURSOR Datatype,MemberId INTEGER);
    sp_mem(mCursor REFCURSOR Datatype, mEmailId INTEGER);
    In the Above Procedures if the second Parameter is Member Id then the first SP will be executed.
    In the Above Procedures if the Second Parameter is MemEmailId then the Second SP will be Executed.
    This is the normal OverLoading Concept inside the package. But for me, i am returning the Recordset using a RefCursor.
    I just want to know it is possible for returning the recordset using ref cursor with the overloading concept for both the SP.
    Thanks,
    Murali.V

    Hello
    You need to be careful with this type of overloading. Overloading is generally based around the position and data types of the parameters being supplied which are used to identify the "signature" of the particular procedure to call i.e.
    sp_myproc(ref cursor, integer)
    sp_myproc(ref cursor, date)
    sp_myproc(ref cursor, varchar2)
    sp_myproc(ref cursor, varchar2, integer)
    etc etc
    When you have 2 procedures that have the same signature, unless you specify the name of the parameter, there is no way to determine which procedure to call:
    tylerd@DEV2> CREATE OR REPLACE PACKAGE pkg_test_overload
      2  IS
      3
      4     PROCEDURE sp_mem(mCursor sys_refcursor,MemberId INTEGER);
      5     PROCEDURE sp_mem(mCursor sys_refcursor, mEmailId INTEGER);
      6
      7  END;
      8  /
    Package created.
    tylerd@DEV2>
    tylerd@DEV2> CREATE OR REPLACE PACKAGE BODY pkg_test_overload
      2  IS
      3
      4     PROCEDURE sp_mem(mCursor sys_refcursor,MemberId INTEGER)
      5     IS
      6
      7     BEGIN
      8
      9             NULL;
    10
    11     END;
    12
    13     PROCEDURE sp_mem(mCursor sys_refcursor, mEmailId INTEGER)
    14     IS
    15
    16     BEGIN
    17
    18             NULL;
    19
    20     END;
    21
    22  END;
    23  /
    Package body created.
    Package body created.
    tylerd@DEV2> var mycursor refcursor
    tylerd@DEV2> var memberid number
    tylerd@DEV2> exec pkg_test_overload.sp_mem(:mycursor,:memberid)
    BEGIN pkg_test_overload.sp_mem(:mycursor,:memberid); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00307: too many declarations of 'SP_MEM' match this call
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    tylerd@DEV2> exec pkg_test_overload.sp_mem(:mycursor,MemberId=>:memberid)
    PL/SQL procedure successfully completed.
    tylerd@DEV2> exec pkg_test_overload.sp_mem(:mycursor,mEmailId=>:memberid)
    PL/SQL procedure successfully completed.To me, using named notation with overloading kind of defeats part of the objective...I'm not saying it's completely wrong, as sometimes I guess it's unavoidable, but I'd review the design carefully :-)
    HTH
    David
    Message was edited by:
    David Tyler
    Oops, copied the wrong bit of the output! :-)

  • ECM functionality and concept...........?

    Hello gurus,
    I am in sap functional testing.
    In 1 case, I created change number 123 for perticular material say X (HALB). Now in MM01, I am creating material Y (FERT) by giving same change nomber as 123. But problem is that , after entering the data , system is changing the name of given material Y to X as per change number given.
    Now my doubt is that, shal i consider it as right concept of ECM and move forward or I need to create seperate change number for seperate matl...........?
    I am not aware about ECM functionality and concept.
    Anyone can clear my query?
    Appreciate your help.
    Regards,
    Shamsher

    You cannot use same material No. for more than one material, for another material you need to use different No.
    In your case, when you put the same no. 123 in mm01, system is thinking you are trying to extend the material already created with no. 123 and is acting accordingly for extending material. We extend material already created to other plant or different view which were not already created for material through mm01. For material change we use mm02.
    Edited by: Afshad Irani on Jun 8, 2010 4:06 PM

  • Function overloading advantage..

    Hi,
    One of the package feature is function overloading i.e same name objects with different parameters or different datatype parameters.
    how does it(function overloading) increase the performance ?
    what are the benefits with function overloading ?
    Thanks in advance.
    RP

    how does it(function overloading) increase the performance ?It doesn't.
    what are the benefits with function overloading ?Consider this:
    SQL> CREATE OR REPLACE PACKAGE pkg AS
      2     PROCEDURE print(p IN VARCHAR2);
      3     PROCEDURE print(p IN DATE, msk IN VARCHAR2 := 'DD-MON-YYYY');
      4     PROCEDURE print(p IN NUMBER);
      5     PROCEDURE print(p IN VARCHAR2, totem IN VARCHAR2);
      6  END;
      7  /
    Package created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE BODY  pkg AS
      2   PROCEDURE print(p IN VARCHAR2) IS
      3   BEGIN
      4    dbms_output.put_line(p||'!');
      5   END;
      6   PROCEDURE print(p IN DATE, msk IN VARCHAR2 := 'DD-MON-YYYY' ) IS
      7   BEGIN
      8    print(to_char(p, msk));
      9   END;
    10   PROCEDURE print(p IN NUMBER) IS
    11   BEGIN
    12    print(to_char(p));
    13   END;
    14   PROCEDURE print(p IN VARCHAR2, totem IN VARCHAR2) IS
    15   BEGIN
    16    print(totem||' '||p);
    17   END;
    18  END;
    19  /
    Package body created.
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL> exec pkg.print(user)
    B!
    PL/SQL procedure successfully completed.
    SQL> exec pkg.print(sysdate)
    07-MAR-2006!
    PL/SQL procedure successfully completed.
    SQL> exec pkg.print(sysdate, 'HH24:MI:SS')
    11:18:59!
    PL/SQL procedure successfully completed.
    SQL> exec pkg.print(1234)
    1234!
    PL/SQL procedure successfully completed.
    SQL> exec pkg.print(user, '>>>')
    B!PL/SQL procedure successfully completed.
    SQL> exec pkg.print(to_char(sysdate), 'HH24:MI:SS')
    HH24:MI:SS 07-MAR-06!
    PL/SQL procedure successfully completed.
    SQL> I can pass any value into my package without having to worry about its datatype. Similarly I can pass different numbers of arguments into the procedure without worrying. Of course, a similar effect can be gained from using default values but we don't always want that.
    Incidentally, note what happened when I passed in a date as a character string.
    Cheers, APC

  • Function overloading ... Is there any benefit ?

    Where is the benefit if I write this ..
    using function overloading :
    add(Integer, Integer);
    add(String, String);
    instead of
    addInt(Integer, Integer);
    addStr(String, String);
    Is there any benefit ?

    why you are saying "add() *does not contain an argument type name*"?The statement that you are still claiming to find unclear was 'embed the argument type names in the function name'. The function name 'add()' doesn't do that. Your alternative function name 'addInt() does do that. 'Int'. A type name. Embedded in the function name.
    Am I missing something ?Yes. I don't see how you can agree that add() is shorter than addInt() without also seeing that the difference consists precisely of the embedded type name. Frankly, I don't think you have been reading very carefully.

  • Function Overloading in sql

     is there any way by which one can over load function with out affecting any change in .net code or sql proc or function which refer that function

    No, there is no way to "overload" a function.
    However, what you are describing can be done by creating a layer of stored procs and views the .Net code calls instead of direct accessing the database.  This gives the SQL developer the ability to change the physical database and change the layer
    to match the same output, without changing the .Net code.
    See "Stored procedures vs dynamic SQL":
    http://msdn.microsoft.com/en-us/library/ee658127.aspx

  • Function overloading on return types

    consider following two overloaded functions
    public int functionA(int a,int b);
    public char functionA(int a,int b)and if i call them like this
    int returnInt = functionA(a,b)
    char returnChar = functionA(a,b)in this scenario which function to call can be decided depending on the
    return type then why java don have overloading on the basis of return type ?

    Try it.

  • What is Functional area concept in SAP, What way it is useful.

    Any body explain the concept of Functional area, in which way it is useful .  give 2/3 examples how to use.

    Hi,
    Functional areas are used to analyse Cost of Sales Accounting. By this you can analyse your organization's expenses by your funtional area like Finance, Marketing, Production, HR and so. If you want to default functional areas in to document then GL master has field of functional area where you can map it.
    Steps for Cost of Sales Accounting.
    1. Crete functional areas - OKBD
    2. Create substitution for cost of sales accounting with call up point 5 - GGB1
    3. Activate cost of sales accounting under SPRO>Financial Accounting>Financial Accounting Global Settings>Company Code>Cost of Sales Accounting>Activate Cost of Sales Accounting for Preparation
    Regards,
    Chintan Joshi.

  • Query Compilation Error - Function overloaded

    I'm trying to use 2 document style web services in a query. When I test the query
    I get:
    tart server side stack trace:
    java.rmi.RemoteException: EJB Exception:; nested exception is:
         java.rmi.RemoteException: Query Compilation Error (Type Checks) 1-3-1-3: Function
    Employees1:ProcessDocument() is overloaded.
    java.rmi.RemoteException: Query Compilation Error (Type Checks) 1-3-1-3: Function
    Employees1:ProcessDocument() is overloaded.
         at com.bea.ldi.server.QueryBean.execute(Unknown Source)
         at com.bea.ldi.server.QueryBean_1ao78o_EOImpl.execute(QueryBean_1ao78o_EOImpl.java:306)
         at com.bea.ldi.server.QueryBean_1ao78o_EOImpl_WLSkel.invoke(Unknown Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
         at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
         at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:821)
         at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
         at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
    End server side stack trace
    Can someone tell me what this error means?
    Thank you,
    Jason

    Release Note Entry:
    When designing Workshop web services, you may need to alter the
    Targetnamespace for a web service if a method name in this web service
    clashes with a method name in another web service that uses the same
    Targetnamespace.
    "Mike Reiche" <[email protected]> wrote:
    >
    "A function with the same name has multiple definitions in the configuration.
    Check
    you configuration"
    Check for multiple definitions of Employees1:ProcessDocument() in your
    CFLD file(s).
    - Mike
    "Jason Levine" <[email protected]> wrote:
    I'm trying to use 2 document style web services in a query. When I test
    the query
    I get:
    tart server side stack trace:
    java.rmi.RemoteException: EJB Exception:; nested exception is:
         java.rmi.RemoteException: Query Compilation Error (Type Checks) 1-3-1-3:
    Function
    Employees1:ProcessDocument() is overloaded.
    java.rmi.RemoteException: Query Compilation Error (Type Checks) 1-3-1-3:
    Function
    Employees1:ProcessDocument() is overloaded.
         at com.bea.ldi.server.QueryBean.execute(Unknown Source)
         at com.bea.ldi.server.QueryBean_1ao78o_EOImpl.execute(QueryBean_1ao78o_EOImpl.java:306)
         at com.bea.ldi.server.QueryBean_1ao78o_EOImpl_WLSkel.invoke(Unknown
    Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
         at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
         at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:821)
         at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
         at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
    End server side stack trace
    Can someone tell me what this error means?
    Thank you,
    Jason

  • JSP 2.0 EL Function Overloading

    Can methods defined as EL functions be overloaded?
    I have a class with two overloaded methods. Both of them are declared with "public static" and one of them is defined as an EL function through a taglib. When trying to invoke the method defined as an EL function, I get an error indicating it's trying to run the other version of the method, not the version defined as an EL function.
    What's weird is that if I rearrange the order of the overloaded methods in my class it works fine. It's as if EL is just looking for the first method with a name matching what's defined in the tablib and attempting to run it.
    I'm running WebLogic Server 10 on WinXP.

    Either declare it non-public or assign it another name.

Maybe you are looking for

  • Why is the fan in my iMac running so much after Mountain Lion update?

    For some reason, I seem to notice the fan on my 4 year old iMac running constantly, even with very few processes running (only Mail and Safari) after the upgrade to Mountain Lion. Anyone else have this problem? Anyone have a solution?

  • Soft Proofing?

    For those here who are having success with their printing. What if anything are you doing about lack of soft proofing in LR. My current situation is, I get acceptable prints only 50% of the time. Everything is color managed of course and I'm printing

  • Cant sign into lightroom mobile from desktop

    Every time I try to sign in with my ID, it says I need to change my password and will send me an email. It doesn't. I've changed it manually, but that didn't fix it either. Any suggestions?

  • Are there any standard Idocs or Bapis for posting the data into transaction

    Hi, Are there any standard Idocs or Bapis for posting the data into transactions ME42N and IK11? Thank You.

  • Problem in the Function module

    Dear All,         I am using the ECC 6.0 with all the service packs applied. when i am creating a function module, i am getting an error like " Tables parameters are obsolete". My requirement is to get the internal table structure what should i do???