Is there a final specification of Java generics?

The longer I look into the draft specification the more mysterious it looks to me. This cannot be the final specification of a new language feature. Does anybody know where the feature is actually specified?
Just as an example: page 13 of the draft spec (dated April 27, 2001) says:
Given the method declarations:
static <A> Seq<A> nil() { return new Seq<A>(); }
static <A> Seq<A> cons(A x, Seq<A> xs)
{ return new Seq<A>(x, xs); }
The following is a legal expression:
cons(new IOException(), cons(new Error(), nil())) // of type: Seq<Throwable>
The generics compiler, however, rejects it saying:      
cons<A>(A,Seq<A>) cannot be applied to (IOException,Seq<Error>)
Frankly said, I think, the compiler is right and the draft specification is wrong. Seemingly the idea of type parameter inference is that each actual argument type is a subtype of the corresponding formal argument type that was found by means of type parameter inference.
In the example above, if type Throwable were deduced for the type variable A, then the first formal method argument were of type Throwable and the actual argument would be of a subtype, namely IOException. Fine. But the second formal method argument would then be Seq<Throwable> and the actual argument is a Seq<Error>, which is not a subtype of Seq<Throwable>. I think, there is no parameter inference possible that makes sense for this example. Hence the compiler rightly rejects it.
I guess, obvious mistakes like this have long been fixed in the specification. Where is the most recent release of the spec? I could not find anything on Sun's website.

Just to be more helpful, my corrected grammar for MethodInvocation is:
MethodInvocation ::= MethodExpr ( ArgumentListOpt )
MethodExpr     ::= MethodName
           |  Primary . TypeArgumentsOpt Identifier
           |  super . TypeArgumentsOpt Identifier
           |  Name . super . TypeArgumentsOpt Identifierwhile the original grammar contained this production:
MethodExpr     ::= TypeArgumentsOpt MethodName
                 |  ...Type arguments in front of an unqualified method name can't be unambiguously parsed, so they have been made illegal. You need to use a primary (a class expression for non-static methods or a class name for static methods) to resolve the ambiguity.
Similarly, the corrected constructor invocation productions are:
ClassInstanceCreationExpression ::= new TypeArgumentsOpt
     ClassOrInterfaceType ( ArgumentListOpt ) ClassBodyOpt
                     |  Primary . new TypeArgumentsOpt
     Identifier TypeArgumentsOpt ( ArgumentListOpt ) ClassBodyOptwhile the original was:
ClassInstanceCreationExpression ::= TypeArgumentsOpt new
                     ClassOrInterfaceType TypeArgumentsOpt
                                            ( ArgumentListOpt ) ClassBodyOpt
                                    |  Primary.TypeArgumentsOpt new
                     Identifier TypeArgumentsOpt
                                            ( ArgumentListOpt ) ClassBodyOpthere the placement of the TypeArguments productions had to be moved in order to resolve grammar ambiguities; in addition "ClassOrInterfaceType" already includes an optional final TypeArguments clause, and so the extra one in the first alternative needed to be removed.

Similar Messages

  • One thing java generics are missing

    specialization!
    I'll give you a templated example with a function here:
    template <typename T>
    inline std::string to_string(const T& t)
    std::istringstream ss;
    ss << t;
    return ss.str();
    that's one of those standard conversion snippets that everyone uses... as long as T supports the "<<" operator, it will convert just fine...
    Now, if you're using this function in other template based code, the problem comes up:
    template <typename T>
    void foo(const T& t)
    std::string s = to_string(t);
    ... do something with s now...
    it makes sense, if you want to do operations with a string... but what if the type T *was* a string... the to_string function just did a whole mess of needless operations (stringstream conversion)...
    here comes template specialization to the rescue:
    template <> inline std::string to_string<std::string>(const std::string& t)
    return t;
    there we go... no extra steps... because it's inlined to begin with, the compiler will remove it... (this is what's called a conversion shim).  Now when the to_string function is called with an std::string argument, it does nothing.

    Hmmm, it seems I didn't explain it too well:
    the 3rd snippit is the same as the first, however the "typename T" has been removed and all instances of "T" have been replaced with a specific type: this is template specialization... it allows for you to have different code for each type... it's a complicated form of function overloading....
    what I'm saying is that, in a java generic collection, you may have all this code that works for all types, but could be optimized for one of those types... I used string above...
    for instance... let's say there's a member function to count the number of characters used if the type were converted to a string... the easiest thing to do would be to convert it to a string an get the length.... however, in the case of numbers, there's a much, much more efficient way to do it (can't recall the algorithm... but you can get the number of digits with division and maybe a log10 or something...)... this is a mundane case, but even if you did want to use that math for the int version of that generic, you couldn't...

  • Is there any final answer to why emails will not send when away from home IP?  Have san diego road runner.  emails send fine from home, but do not send when using another IP.

    Is there a final answer to why emails do not send from iphones when away from home IP?

    This is a common anti-spam technique for ISPs to prevent mail from being sent from anywhere other than your service location. Ask Road Runner if there are any specific settings you can use to circumvent this.

  • Is there a goto statement in java??

    is ther a goto statement in java
    if yes how is it
    and if no wat we use instead of it , if we want to redirect to control flow??
    thanking you
    rose!!!

    But he did not say it with three exclamation
    points!!!
    yes, I'm trying to restrict my usage of the exclamation mark as part of my attempts to be more even tempered (which aren't succeeding that well, but I may just need more practice).

  • Hi All, We are in to Release 11.5.10.2.There is a specific requirement to Prevent users from creating Manual Sales Orders in oracle and yet users should be able to book the Sales Orders Imported from CRM system into Orcale.Please advise.

    Hi All, We are in to Release 11.5.10.2.There is a specific requirement to Prevent users from creating Manual Sales Orders in Oracle and  yet users should be able to book the Sales Orders Imported from CRM system into Orcale.Please advise.

    Thanks for your advise.
    However, I missed to mention that we have two set of users  One is for Finished Goods and another for Spares.
    Only Spares users need to be prevented from creating Direct/Manual Sales Orders in Oracle.
    As you suggested, if this will be done at Form level, that may Disallow FG users also to create Manula Sales Orders which should not be the case.
    Further, I tried to test one scenario through Processing Constraints but it did not work.
    Application
    OM
    Validation Type
    Entity
    Temp
    Short Name
    TBL
    Validation Semantics
    Created By
    Equal To
    User(Myself)
    Processing Cosntraint
    Application
    OM
    Entity
    Order Header
    Constraint
    Operation
    User Action
    Create
    Not Allowed
    Conditions
    Group
    Scope
    Validation Entity
    Record Set
    Validation Template
    101
    Any
    Order Header
    Order
    Above Created
    Please advise.

  • Can someone help me understand this? (java generics wildcards)

    Hi all.
    First of all this is my first post on sun forums. Besides that i only used java for few weeks now and i think java is quit a nice language.
    I do have a question regarding java generics and wildcard casting (if you can call it that).
    Assume you have following code.
    public class Test <T extends Number> {
         private T x;
         Test(T x)
              this.x = x;
         T getX()
              return x;
         <U extends Number> void setX(U x)
              this.x = (T)x;
    public class Main {
         public static void main(String[] args) {
              Test<Integer> p = new Test <Integer>(5);
              System.out.println(p.getX());
              p.setX(53.32);
              System.out.println(p.getX());
    }This compiles with following results:
    5
    53.32
    Question:
    First: If I declared p to be of type Test<Integer> then why did x in Test class changed its type from Integer to Double?
    Second: Is this a possible unchecked casting behavior? and if so why does this work but doing something like this :
    Integer x = 5 ;
    Double y = 6.32;
    x=(Integer)y;fails with compile time error?

    Hello and welcome to the Sun Java forums.
    The behavior you describe would not occur if your setX(?) method used T instead of another type constraint.
    However, let's look at why it works!
    At line 1 in main, you create your Test with a type parameter of Integer; this becomes the type variable T for that particular instance of Test. The only constraint is that the type extends/implements Number, which Integer does.
    At line 2 you obtain a reference to a Number, which is what getX() is guaranteed to return. toString() is called on that object, etc.
    At line 3 you set the Number in the Test to a Double, which fits the type constraint U extends Number, as well as the type constraint T extends Number which is unused (!). Note that using a different type constraint for U, such as U extends Object or U super Number, could cause a compile-time error.
    At line 4 you obtain a reference to a Number, which is what getX() is guaranteed to return.
    The quirky behavior of setX is due to the second type constraint, which is obeyed separately; in this case, you probably want to use void setX(T x) {
    this.x = x;
    }edit: For the second part of your question, x = (Integer)y; fails because Integer and Double are distinct types; that is, Integer is not a subclass of Double and Double is not a subclass of Integer. This code would compile and work correctly: Number x = 5 ;
    Double y = 6.32;
    x=y;s
    Edited by: Looce on Nov 15, 2008 7:15 PM

  • In firefox, the video from website "tv.vu.edu.pk" is not displaying even i have installed the latest version of JAVA. There rotates a circle around java monogram every time but video is not playing even it is working fine with internet explorer

    In firefox, the video from website "tv.vu.edu.pk" is not displaying even i have installed the latest version of JAVA. There rotates a circle around java monogram every time but video is not playing even it is working fine with internet explorer

    It's not working here as well with Java 6 U25 on Linux.

  • Where to find Java Class File Specification for Java 5.0?

    Where to find Java Class File Specification for Java 5.0?
    thank you in advance.

    same place you found it for 1.4Can u give more details? I thought the class spec for Java 1.4 is the same as Java 1.2.
    anyone can tell where to find Java Class File Specification for Java 5.0?
    Thanks.

  • Are there non-public classes in Java SDK?

    Or are ALL classes in all packages of the Java SDK public?
    I have looked in the sources spot checking and didn't find a non public (default) class.
    If all classes are public, why?
    There exists a means in Java language to define a class as default ("class MyClass" instead of "public class MyClass") visibility. So why isn't it used by Java SDK (if this is really true)?

    I dont know what language you're programming in.
    If you don't specify
    public class
    or
    private class
    the class is "protected".
    Read the spec.If you read the spec, you'll see that, with respect to a class:
    (per section 6.6.2) Classes from outside the package the class lives in that extend the class have access to protected members.
    (per section 6.6.5) Classes from outside the package this thing lives in that extend this class do not have access to default members.
    Relevant part of section 6.6.5 (Example: Default-Access Fields, Methods, and Constructors) is:
    If none of the access modifiers public, protected, or private are specified, a class member or constructor is accessible throughout the package that contains the declaration of the class in which the class member is declared, but the class member or constructor is not accessible in any other package.
    This is default access, not protected access
    Lee

  • I installed lv 6.1 on a windows 98 system. As I am having problems of stability (much more than with the former release 6.0), I would like to know if there is some specific problem with windows 98 or there is some patch.

    I installed lv 6.1 on a windows 98 system. As I am having problems of stability (frequent crashes, much more than with the former release 6.0), I would like to know if there is some specific problem with windows 98 or there is some patch available.

    My experience with Win98 is that it is not a very stable system, regardless of software used. For example, Win2000 and XP are far more stable than 98. I've had it crash on its own if I leave the computer on for several days.
    I wouldn't recommend running programs for long time (few days) on this OS.
    This being said, can you be more specific in your question. What kind of stability problems did you have, which VIs did you run (if possible post them here), did you change the interrupts and priority levels on those VI, do you get error messages or blue screen....
    Zvezdana S.

  • Is there any final cut express 4.0.1 update available?

    Is there any final cut express 4.0.1 update available? I want a RELIABLE source to update this, preferably by APPLE, Inc.
    I'm VERY disappointed that APPLE does not have that on the website. I SUPPORTED you by buying a product and in return you do NOT have a place for us to install upgrades especially if consumers like me got a new laptop. That is just plain MEAN. I mean, REALLY.
    Thank you and I hope to get this as soon as possible.

    Final Cut Express was discontinued 3 years ago (June 2011).  It was replaced by Final Cut Pro X.
    FCE is no longer supported by Apple.  That does not mean it won't run on Lion, Mt. Lion, Mavericks or Yosemite, however with each successive upgrade to OS X it becomes less & less likely that FCE will be installable or even run properly after being installed, because it is so much older than the current versions of OS X.   That said, the FCE 4.0.1 update is still available through Software Update provided you already have FCE 4.0 installed on your Mac.  The 4.0.1 update is not available "publicly," meaning you can't search for it on Apple's website and find it; FCE 4.0 has to already be installed on your Mac and you have to update it via Software Update on your Mac.
    One forum contributor DID find a way to download the 4.0.1 update without using Software Update, see this thread -> Where can I download Final Cut Express 4.0.1?
    My advice is to move to Final Cut Pro X since you have a Mac running Mavericks (10.9.5).
    I understand your frustration at having purchased some software and now you can no longer use it.  However, obsolescence is a natural part of the technology world.  FCE is now obsolete and has been replaced by Final Cut Pro X.   If you have OS X Lion or any later version of OS X installed on your Mac, you should be looking at Final Cut Pro X.

  • How to represent java generics in UML

    Hello,
    Can anyone tell me how to represent java generics in UML? Say I have ClassA<ClassB>. How do I represent this in UML?
    Thanks in advance,
    Julien Martin.

    More formally you can use parameterized types.
                : T:Classifier :
      +---------:..............:
      |    ClassA    |
    <<bind>> <T -> ClassB>
    | ClassA<ClassB> |
      Which may be useful if you have different instantiations of ClassA<T> with different values of T.
    Pete
    (I really must get round to making an ascii art UML editor sometime)

  • How find system specification in java

    is it possible to find out system specification in java e.g. motherboard, bios vendor & serial id etc.

    Welcome to the Forums.
    Please go through the FAQ of the Forum.
    You has posted your query in the wrong Forum, this one is dedicated to Oracle Forms.
    Please try {forum:id=1050}.
    Regards,

  • I'm trying to update my Photoshop CS5, but continue to receive the same problem every time. The application manager update dialogue box simply states "some updates failed to install." There's no specific error code, but a link to contact support for furth

    I'm trying to update my Photoshop CS5, but continue to receive the same problem every time. The application manager update dialogue box simply states "some updates failed to install." There's no specific error code, but a link to contact support for further assistance. It doesn't take me to customer support, but does take me to a screen which states. "Error "This serial number is not for a qualifying product." I've checked my account and the product serial number is associated with my account., so I don't see any problem.  I have not been able to find a resolution to this problem, so I hope that someone can point me in the right direction.  Thank you!

    update directly, Product updates

  • I would like to restore my iphone to ios 4.3.5 from 5.0.1. i've tried and watched videos over youtube  and it doesn't helps. is there any other specific way? the ios 5.0.1 makes my phone crash and drains my battery whenever i tried to switch it back on.

    i would like to restore my iphone to ios 4.3.5 from 5.0.1. i've tried and watched videos over youtube  and it doesn't helps. is there any other specific way? the ios 5.0.1 makes my phone crash and drains my battery whenever i tried to switch it back on. kindly help me.

    There is no legit way to do this at all.

Maybe you are looking for

  • [Solved] The "¨^~"-key does not work for me in URxvt in Awesome

    Hello. I can not understand why I can not write e.g. ^ or ~ using the "^¨~"-key on my keyboard (norwegean layout) in URxvt (extra/rxvt-unicode) in Awesome WM (aur/awesome-git). Although I have tested in other window managers e.g. dwm, and the key wor

  • DVD playback on a MAC - help!

    Hello, To be honest I'm not too sure if my post should be in here or in the Encore forum. The problem I'm having is whislt a compiled encore DVD is being tested on a Mac. After each video is watched it is set up to return to main menu screen, but for

  • Transfer price without Material Ledger

    Dear Expert, I am not using material ledger.but how i will handle transper price without material ledger I am going to do stock transfer of  FG stock from Plant A to plant B. Standard price in plant A is 10 rs and Plant B 15rs FG stock in Recieving p

  • .ipsw file in my trash?

    I just happened to look in my trash and noticed that this file was there: iPhone3,14.3_8F190Restore.ipsw I never deleted any files like this, so I don't know how it ended up there. I have an iPhone 4 that has been running ios 4.3 since it came out bu

  • Searching .php files - previous suggestions not working

    I'm having a problem getting previous suggestions to work in indexing my php files. I do development in and out of my sites folder, but I can't get any of my php files' content to index. I've added this line to the source code importer: <string>publi