How to determine method signature

Consider the following compilation unit in Java where ecran.afficher essentially is System.out.println. I do not understand why no error is detected at compile-time. According to me, at least the call d.m(d,c) is incorrect. There is an ambiguity between methods A.m(D, A) and D.m(A, A). But the compiler choses A.m(D, A). I cannot figure out why.
class A
void m(A x, A y){ ecran.afficher("A.m(A, A) -- stop") ; }
void m(D x, A y){ ecran.afficher("A.m(D, A)") ; m(y, x) ; }
class B extends A
          void m(A x, A y){ ecran.afficher("B.m(A, A)") ; y.m(x, x) ; }
          void m(B x, A y){ ecran.afficher("B.m(B, A)") ; y.m(x, x) ; }
          void m(A x, C y){ ecran.afficher("B.m(A, C)") ; y.m(x, x) ; }
class C extends B
void m(A x, A y){ ecran.afficher("C.m(A, A)") ; x.m(y, this) ; }
          void m(B x, A y){ ecran.afficher("C.m(B, A)") ; x.m(y, this) ; }
          void m(A x, C y){ ecran.afficher("C.m(A, C)") ; x.m(y, this) ; }
class D extends A
void m(A x, A y){ ecran.afficher("D.m(A, A) -- stop") ; }
class Q3
public static void main(String[] args){
A a = new A() ; B b = new B() ; C c = new C() ; D d = new D() ;
          A w = d ; A x = b ; B y = c ; A z = c ;
          d.m(d, c) ;
          d.m(x, y) ;
          z.m(a, b) ;
          c.m(d, x) ;
          y.m(z, a) ;
}

Thanks for giving me the pointer to the Specification
(third edition). Thus as far as I can
understand it, something fundamental has changed from
the second to the third edition. Now the class where
the method is declared is no longer taken into
account.
I suppose that this change is considered acceptable
by the Java designers since it increases the number
of accepted programs. My program is rejected by the
first two versions of the specification, not by the
third one.
I really feel it a bad idea to change such
fundamental aspects.I disagree.
As far as I can tell, the way the 2nd ed. is worded is a bug. I believe that the behavior you observe is what was intended all along, but that strict adherence to JLS 2nd ed. would lead to a compile time error due to ambiguity. A cannot be converted to D by method invocation conversion, so neither method matches both of the conditions.
I could be missing something though.
When the JLS has bugs--following it strictly leads to behavior that differs from the authors' intent--inconsistencies, or ambiguities, it must be revised. Naturally, the addition of new language features also requires revision of the spec.
At the same times, Java becomes so complex that I
really doubt that somebody is still able to write
correct programs in Java (i.e., a priori, not by
trial and error).I don't consider that a problem. Except for minimal, toy programs, I've never written a program that was perfect the first time. Nor do I need to. The compiler finds certain kinds of errors much more quickly and accurately than I ever could, and unit testing takes care of most of the rest.
Now, if you mean that nobody is able to write reasonably bug-free code with a reasonable amount of time and effort, I disagree. But that's entirely subjective anyway.
When I started to teach Java, I spent many days
reading the specification (first edition) carefully.
A few years later, I bought the second edition. But I
found the changes so complex (the new author is
credited as a "programming language theologist" !)
that I almost immediately decided to stick to the
first edition for ever.Then you have to live with the bugs and shortcomings of that editon. You also have to stick with using the corresponding version of the compiler (1.1 or whatever), or have a lang spec. that doesn't match the compiler that implements it.
Now, looking at the cryptic description of the third
edition, I just can say : "The world is getting
crazy". Who could possibly understand and use that ?I don't see the problem. It took me about ten minutes of fairly intesnse concentration to understand the relevant bits. It's not Dr. Seuss, but then, it's not intended to be. A general purpose computer language that has the kinds of features Java does is inherently complex. It requires a complex spec to define it precisely and accurately.
The problem is that I am teaching Java as a first
programming language in my University.That's reasonable. However, I don't think that Java's goals ever included being simple enough and unchanging enough to be easily grasped in its entirety by entry level university students.
I have to say
to my students : This language is changing all the
time. Yes. As are huge tracts of the technology landscape. It's the nature of the beast.
Also my demonstration programs are behaving
differently each year ! That sounds odd. Most of Java's changes as it moves forward have allowed programs written with earlier versions to compile and run unchanged with newer versions.
And I am forced to use the
latest version of the JDK, always bigger and bigger.Forced by whom? By you school's policy?
And I hate it !At the risk of sounding condescending, if you are that resistant to change, computer science may not be the ideal field for you.
Now what shall I do ? Since I will refuse trying to
read and understand the third editionNow it sounds like you're pouting. "My job is too hard. I won't do it. I won't I won't I won't."
(and the
fourth, the fifth...), I will probably teach an
hypothetical Java, invented by myself, and "directly
understandable". ("Tout ce qui n'est pas direct est
nul." (E.M. Cioran))That's your choice, I guess, but if you don't inform your students very clearly and emphatically that said language is something idealized for your convenience and doesn't reflect the real world, then you'll be doing them a great disservice (and possibly be violating Sun's license agreements or trademarks).

Similar Messages

  • How to determine method name at runtime

    hello,
    i try to get method name at runtime..i have a logger and i need this info for logger
    private void method(){
    myLogger.debug( "exception in " + getExecutedMethod() ); /* output should be: exception in method */
    }best regards
    cem

    bcem wrote:
    what i needed was
    [http://today.java.net/pub/a/today/2008/04/24/add-logging-at-class-load-time-with-instrumentation.html|http://today.java.net/pub/a/today/2008/04/24/add-logging-at-class-load-time-with-instrumentation.html]
    regards
    cemYou could also use AOP to add logging. But really, any sort of injected logging is going to be of limited value, since it's very generic and "this method was called with these parameters"-esque. Explicit logging is a lot more descriptive and useful, particularly to support staff who probably won't know what any particular method does

  • Generic method signatures

    I've searched but can't find that a question I have has been asked (or answered). I apologize in advance if it has. Here is my question.
    In Java Generics FAQ by Angelika Langer states in FAQ 802 ( [http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ802] ) "the type parameters of a generic method including the type parameter bounds are part of the method signature."
    In FAQ 810, many examples are presented of method declarations, including generic ones, and their corresponding method signatures. For example,
    <T> T method(T arg) has the following signature in the example:
    <$T1_extends_Object>method($T1_extends_Object>)
    It would seem to be intuitively clear that the type parameter and bounds would be part of the method signature but I can't seem to find such a stipulation/requirement of such in the Java Language Specification. Anybody know where it's stipulated in the JLS?
    Best Regards

    user13143654 wrote:
    Yeah, I know. The title of the subsection is "Determining Method Signature," but then it never seems to expressly do that other than in some ephemeral wafting byproduct of overload resolution.I wouldn't call it "ephemeral" and "wafting." It's pretty specific. If you're looking for the $T1_extends_Object notation, you won't find it. That's not part of the spec.
    I can't seem to find a specific spot in the subsection where I can say "OK, now I've got the method signature and now can proceed to ..." Well, it goes on to Phase 3, and then on to 15.12.2.5 Choosing the Most Specific Method. I'm not sure what you're looking for. It does describe in detail how we get from all the methods in the universe, to which type's methods we'll be considering to which signatures could match to which one is the best match. I don't know what else you're looking for.
    If you're looking for somebody to digest, translate, and simplify all that for you, good luck, but it ain't gonna be me. :-)
    If you have specific questions about smaller pieces of it I (or somebody else) might be able to help out. At the moment though, your question is rather vague.
    Edited by: jverd on May 3, 2011 1:48 PM

  • How is the Method Parameter Identified in this Code Snippet ?

    package methods;
    public class Me10 {
         public static void main(String[] args) {
              short y=6;
              long z=7;
              go(y);
              go(z);
         public static void go(Short s)
              System.out.println("SHORT");
         public static void go(Long l)
              System.out.println("LONG");
         public static void go(int i)
              System.out.println("INT");
    O/P :
    INT
    LONGEven when y is declared as short why does the INT method get called ?
    What can we do so that when i pass y , short method will be called ?
    Thabks in Advance.

    as far as I understand, method parameters are identified per JLS section 15.12.2 'Determine Method Signature':
    "...This step uses the name of the method and the types of the argument expressions to locate methods that are both _accessible_ and applicable, that is, declarations that can be correctly invoked on the given arguments. There may be more than one such method, in which case the _most specific_ one is chosen. The descriptor (signature plus return type) of the most specific method is one used at run time to perform the method dispatch...
    ...The informal intuition is that one method is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error..." [...click here to continue reading if you're interested|http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.12.2|JLS 15.12.2 'Determine Method Signature']
    As for calling 'Short' method for 'y' value, I'd probably use something like go(new Short(y))

  • How to search OER for method signatures

    I would like to search OER for Service assets that have a specific input and/or output. I'm sure this is easy to do but am missing something.
    I was reading the description in the Sample Interface - Account Detail Interface shipped with OER and it says....
    "Users may search for particular method signatures, find this asset, and from here discover the services that implement this interface."
    That's what I want to do but am not sure how to do it. Can anyone explain how I would go about doing that?

    Try a simple search, put the method name in the search box, select the type as All Type. The search will list down the Interface and the Service that contains the api.

  • How to determine the field size

    I am going to make a multiplatform application that hopefully
    will run on linux and windows 2000.If the os is 2000, then I will use
    vb.net/aspx else I'll use java servlets. I make the connection
    to the web server ( through HTTP) not directly to database server.
    So, the resultset will be stored in the String object. The columns
    will be separated by delimeter. Our problem is how to determine
    the size and type of the fields of mssql,oracle and postgres database
    so that we can include it in the String object.
    Ex.
    String sResultSet=new String();
    ResultSet rs=statement.executeQuery(sSQL);
    while(rs.next()){
    sResultset=sResultSet + rs.getString(field1) + "||" + rs.getString(field2) + "||";
    vertical bars acts as delimeter
    supposedly this is the code:
    sResultset=sResultSet + rs.getString(field1) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||" + rs.getString(field2) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||";
    supposedly this is the code if rs.getFieldType() and rs.getFieldSize() methods are existing
    Anyone can give me an idea how to get the field type and field size of the database?
    thanks in advance

    Yes, but I dont know how to do it.
    Can you give me an example of using it.
    Thanks in advance

  • How to determine the solution's ID in absl?

    Hello Community,
    I have a simple question yet I fear there is no simple answer (possibly no answer at all).
    The question is:
    Does any body know ways how to determine the ID (e.g. Y123ABCDY_) of the solution the code is running in?
    My use case is the following:
    We have a solution template which will be deployed in different customer tenant.
    Thus, each deployment will have a different solution ID.
    Now, somewhere in code, we generat PDFs using the OutputManagementUtilities.GetPDF reuse library.
    This method requires the form template code of the pdf to be generated as a parameter.
    However, this PDF form template code is composed of the solution ID and a fixed suffix.
    Thus, currently I need to modify the absl code in each customer installation to manually modify the form template code prefix to the solutions solution ID.
    Therefore I'd like to construct the form template code in absl but for this I need a way to determine the solution's ID.
    Any ideas?
    Best regards,
    Ludger

    Hi Fernando.
    After reading your post I initially thought "what is the ObjectTypeCode" supposed to do any good to determine the solution ID"?
    Using the Object Type code of a custom bo is indeed a way to solve this problem.
    With a little additional code I can extract the relevant solution ID part from there.
    Thanks for the hint, that was really useful.
    Best reegards,
    Ludger

  • How to determine the Support Team from Reported-by?

    Hi All,
    We need to determine the support team based on reported-by.
    I have concluded it is only possible by customization of developing ZBADI from these threads:
    Re: How to determine the Support Team from the Reported by?
    Automatic determination support team based on own specs?
    Re: Route tickets based on Message creaters's location
    So we have created ztable which has relation between SAP component, Reported-by and Support Team.
    Now i need to develope a ZBADI  and assign to the action definition SLFN0001_ADVANCED_FIND_PARTNER(i hope).
    Can anyone help me out with the piece of code. Because i don't which FMs to be called for read and update the support desk message.
    Note: Action definition SLFN0001_ADVANCED_FIND_PARTNER uses method call Z_CRM_DNO_PARTNER_1(which is a copy of CRM_DNO_PARTNER_1 and applied some correction as per note: 1041455).
    Thanks in advance.
    Regards
    Sanjai

    closing this thread.

  • How to determine the file system on Solaris

    Friends,
    How to determine which file system I have installed UFS or ZFS on Solaris
    Thanks

    Other methods would include looking at the /etc/vfstab if it's in there or fstyp(1M):
    System Administration Commands fstyp(1M)
    NAME
    fstyp - determine file system type
    SYNOPSIS
    fstyp [-a | -v] special [:logical-drive]

  • How to determine the support team in service ticket

    Hi all,
    can u guide me how to determine the support team in service ticket,
    when ticket is created from customer system.is there any another way other than organizational structurel settings.
    Thanks and regards,

    Hi Venu,
    You can get it done by development to determnie the support team , other tan org model settings
    1.Develop the z table which will allow to maintain Sold to Party, Component, Support team
    2. Implement the Badi for which will read the sold to party and component from the ticket and look in to ztable and fetch the corresponding support team and audate the support team feald in ticket.For this to take help of ur Abaper
    3. For this to call the BADI have to confgure the actions with method call.
    If u have any query revert
    Regards,
    Basha.

  • Deciding when to use "final" in method signatures

    Please consider this source code:
    public void foo(final Set<String> set) { ... }People who use this class don't need to know that the "set" reference is "final", right?
    Edited by: dpxqb on Apr 30, 2010 3:28 AM

    Kayaman wrote:
    They should be implicitly final so there would be no need for questions like this.I don't understand what that means.
    Or does someone here admit to having a habit of reassigning the parameters?I don't understand. I do it when it needs doing. Here is an example where I re-assigned the reference in the method signature:
    void foo(Writer w) {
      int i = 0;
      boolean hit = false;
      BufferedWriter bw = new BufferedWriter(w);
      Set<String> set = new HashSet<String>();
      bw.write(c);
      w.write(c); // no exception thrown. the object on the other end of the Writer will act weird
                  // which further masks the bug.
    }There are two working Writers going to the same location. There is no reason for this, it makes no sense, and it is a bug waiting to happen.
    This is how I got my BufferedWriter. Reassign the initial reference:
    void foo(Writer w) {
      if(! (w instanceof BufferedWriter)) {
        w = new BufferedWriter(w);
    }The only way to write is via a single object. It just prevents me from doing something stupid. I feel safer by eliminating unused references.

  • Changing exception clause in method signature when overwriting a method

    Hi,
    I stumbled upon a situation by accident and am not really clear on the details surrounding it. A short description:
    Say there is some API with interfaces Foo and Bar as follows:
    public interface Foo {
       void test() throws Exception;
    public interface Bar extends Foo {
       void test();
    }Now, I find it strange that method test() for interface Bar does not need to define Exception in its throws clause. When I first started with Java I was using Java 1.4.2; I now use Java 1.6. I cannot remember ever reading about this before and I have been unable to find an explanation or tutorial on how (or why) this works.
    Consider a more practical example:
    Say there is an API that uses RMI and defines interfaces as follwows:
    public interface RemoteHelper extends Remote {
       public Object select(int uid) throws RemoteException;
    public interface LocalHelper extends RemoteHelper {
       public Object select(int uid);
    }As per the RMI spec every method defined in a Remote interface must define RemoteException in its throws clause. The LocalHelper cannot be exported remotely (this will fail at runtime due to select() in LocalHelper not having RemoteException in its clause if I remember correctly).
    However, an implementing class for LocalHelper could represent a wrapper class for RemoteHelper, like this:
    public class Helper implements LocalHelper {
       private final RemoteHelper helper;
       public Helper(RemoteHelper helper) {
          this.helper = helper;
       public Object select(int id) {
          try {
             return (this.helper.select(id));
          } catch(RemoteException e) {
             // invoke app failure mechanism
    }This can uncouple an app from RMI dependancy. In more practical words: consider a webapp that contains two Servlets: a "startup" servlet and an "invocation" servlet. The startup servlet does nothing (always returns Method Not Allowed, default behaviour of HttpServlet), except locate an RMI Registry upon startup and look up some object bound to it. It can then make this object accessible to other classes through whatever means (i.e. a singleton Engine class).
    The invocation servlet does nothing upon startup, but simply calls some method on the previously acquired remote object. However, the invocation servlet does not need to know that the object is remote. Therefore, if the startup servlet wraps the remote object in another object (using the idea described before) then the invocation servlet is effectively removed from the RMI dependancy. The wrapper class can invoke some sort of failure mechanism upon the singleton engine (i.e. removing the remote object from memory) and optionally throw some other (optionally checked) exception (i.e. IllegalStateException) to the invocation servlet.
    In this way, the invocation servlet is not bound to RMI, there can be a single point where RemoteExceptions are handled and an unchecked exception (i.e. IllegalStateException) can be handled by the Servlet API through an exception error page, displaying a "Service Unavailable" message.
    Sorry for all this extensive text; I just typed out some thoughts. In short, my question is how and why can the throws clause change when overwriting a method? It's nothing I need though, except for the clarity (e.g. is this a bad practice to do?) and was more of an observation than a question.
    PS: Unless I'm mistaken, this is basically called the "Adapter" or "Bridge" (not sure which one it is) pattern (or a close adaptation to it) right (where one class is written to provide access to another class where the method signature is different)?
    Thanks for reading,
    Yuthura

    Yuthura wrote:
    I know it may throw any checked exception, but I'm pretty certain that an interface that extends java.rmi.Remote must include at least java.rmi.RemoteException in its throws clause (unless the spec has changed in Java 1.5/1.6).No.
    A method can always throw fewer exceptions than the one it's overriding. RMI has nothing to do with it.
    See Deitel & Deilte Advanced Java 2 Platform How To Program, 1st Ed. (ISBN 0-13-089650-1), page 793 (sorry, I couldn't find the RMI spec quick enough). Quote: "Each method in a Remote interface must have a throws clause that indicates that the method can throw RemoteException".Which means that there's always a possibility of RemoteException being thrown. That's a different issue. It's not becusae the parent class can throw RE. Rather, it's because some step that will always be followed is declared to throw RE.
    I later also noticed I could not add other checked exceptions, which made sense indeed. Your explanation made perfect sense now that I heard (read) it. But just to humour my curousity, has this always been possible? Yes, Java has always worked that way.
    PS: The overwriting/-riding was a grammatical typo (English is not my native language), but I meant to say what you said.No problem. Minor detail. It's a common mistake, but I always try to encourage proper terminology.

  • Method signature of a two dimensional array of an object

    Hi,
    Does anyone know how to set the method signature of a two dimensional array of an object (e.g. : String[][]).
    Thank you.

    using javap for the following function:
    public int testFunction(String myStr[][]);
    public int disconnectServer(java.lang.String[][]);
    /* ([[Ljava/lang/String;)I   */
    so the signature is:
    ([[Ljava/lang/String;)I                                                                                                                                                                                                                                                                                                                                                                                                                                                            

  • How to determine is it SMB - Remote SAM server access , false positive?

    How to determine is it SMB - Remote SAM server access , false positive?

    5583-0 right?
    I would say that there are different types of false positives. Do you mean, how do I determine if what what was seen actually represents an attempt to access the SAM database? I would start by looking at MySDN (or whatever Cisco is calling it these days...intellishield?). It's often not very up to date and missing information, but it's an easy thing to check. Here's the link for this sig:
    https://intellishield.cisco.com/security/alertmanager/ipsSignature?signatureId=5583&signatureSubId=0
    If you look at the benign triggers, you'll see that it suggests that this only matters if the source is external. It's up to you whether to research any further. If you really want to inspect the signature further, you'll have to add one of the "log packets" actions. This will save a network trace when it fires again and then you can open it up in Wireshark, which understands SMB and will probably decode it enough for you to verify whether it actually was an attempt to access the "Remote SAM server".

  • Interface method Signature...

    Hi all,
    Is there any Function Module that can be used to modify
    the signature of a method in an interface from code??
    I want to write a FM that imports the interface and
    method name and changes the method signature..
    Pls Help.
    Thanks in advance.

    Here is a sample program which will give you thep signature of the class/methods.    I'm not sure how to update them, or if it is a good idea to do so.
    report zrich_0003.
    data: l_dref  type ref to cl_abap_typedescr.
    data: l_clref  type ref to cl_abap_classdescr.
    data: x_methods type abap_methdescr.
    data: x_parameters type abap_parmdescr.
    constants: query_class type seoclsname
                        value 'CL_GUI_ALV_GRID'.
    * check if query_class exists in the current system
    call method cl_abap_classdescr=>describe_by_name
      exporting
        p_name         = query_class
      receiving
          p_descr_ref = l_dref
      exceptions
        type_not_found = 1
        others         = 2.
    if sy-subrc <> 0.
      exit.
    endif.
    l_clref ?= l_dref.
    loop at l_clref->methods into x_methods.
      write:/ x_methods-name.
      loop at x_methods-parameters into x_parameters.
        write:/     x_parameters-length,
            x_parameters-decimals,
            x_parameters-type_kind,
            x_parameters-name,
            x_parameters-parm_kind     .
      endloop.
      skip 3.
    endloop.
    Regards,
    Rich Heilman

Maybe you are looking for

  • Did you know when you type in your email in google your behance pdf resume shows up? This is a security breach!

    I typed my email address in Google and my Behance pdf resume shows up with all my information. Did you all know this? This is a security breach in my opinion. Message was edited by: Carol Smith

  • Cisco ISE Guest Authentication Failed : 86020: Unknown exception

    Hi, I would like to check what may be causing the error message 86020:unknown exception for ise when guest user authenticates via wireless using CWA? I have also attached a screen capture of the error and after the authenitcation logs change to authe

  • JEE 2 Source code

    Hi, is the source code of Java EE 5 available for downloading anywhere? Regards,

  • Tabmenu in a JSF page

    hi all, I am supposed to create an Application in JSF.Functionality is to create a page with multiple tab items that display different pages for each tab. The main concern is that i need the tab menu to in the middle of the page , meaning , the page

  • Camera raw v4.41

    i am using windows vista ultimate.i encountered this problem (below) while downloading camera raw 4.41 for my adobe cs3. any help will be appreciated. Adobe reader could not open camera_raw_4_4_1.zip because it is either not a supported file type or