Ternary + generics doesn't compile

why doesn't the following compile?
import java.util.ArrayList;
import java.util.List;
public class Test
List<String> method()
return true ? getListA() : getListB(); // doesn't compile
static <T> List<T> getListA()
return new ArrayList<T>();
static <T> List<T> getListB()
return new ArrayList<T>();
If you expand the ternary opeartor into an if-then-else it works. Also if you cast the results of getListA() and getListB() it works. Seems counter intuitive.

Followup: I'm guessing the latter, because changing it to import java.util.*;
public class Test
    List<String> method()
        //return true ? getListA() : getListB(); // doesn't compile
        return ternary(true, getListA(), getListB());
    static <T> T ternary(boolean b, T left, T right)
        return b ? left : right;
    static <T> List<T> getListA()
        return new ArrayList<T>();
    static <T> List<T> getListB()
        return new ArrayList<T>();
} doesn't help.

Similar Messages

  • IPE doesn't compile

    Hi,
    I just stumbled upon IPE and would like to try it. It's available in AUR (this is why I love AUR :-), but sadly it doesn't compile fully. It finishes with:
    Compiling image.cpp...
    g++ -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -Wall -g -O2 -fpic -DIPEUI_QT -I../../include -c -o ../../../build/obj/ipelets/image.o image.cpp
    image.cpp:33:23: fatal error: QFileDialog: No such file or directory
    compilation terminated.
    make[1]: *** [../../../build/obj/ipelets/image.o] Error 1
    make[1]: Leaving directory `/tmp/yaourt-tmp-andre/aur-ipe/src/ipe-7.1.1/src/ipelets/image'
    make: *** [ipelets/image] Error 2
    It seems, that the same error appears while manual compilation. It is quite active developed and also the AUR entries are quite new, so I hope someone involved or who had the same problem can help me.
    Regards,
    André

    https://aur.archlinux.org/packages.php?ID=7971 installed just fine using makepkg.
    QFileDialog is provided by qt - do you have it installed?

  • Why the following doesn't compile

    Can someone explain me why the following doesn't compile:
    class A<N extends Number> {
        public LinkedList<String> list;
        public N getN() {
            return null;
    class Test {
        Test(A a) {
            Number n = a.getN();
            String str = a.list.getFirst();
    }The compiler error is:
    incompatible types
    found   : java.lang.Object
    required: java.lang.String
            String str = a.list.getFirst();And if compiler "lose" generic info for some reason or other, so it don't know type "a.list.getFirst()" anymore and think that it's Object, then why it know type of "a.getN()"?

    DrClap wrote:
    I'm not convinced by that explanation. I've used List<Whatever> in classes which aren't themselves generic and it works as I and the OP expect it to work. And I don't really see the difference between a class which isn't generic and a class which could be generic but isn't. I also don't see why public members should be treated differently when accessed from outside a class compared to when accessed inside a class.
    If it indeed doesn't compile (and I haven't tested that myself) then no doubt there's a reason for that, this isn't one of those convoluted examples which the compiler writers could have missed without anybody noticing. It just doesn't seem to me that what jtahlborn wrote is actually the reason.Jtahlborn was correct with his explanation: whenever you use a generic type as the corresponding "raw type", the type loses all its generic features.
    Thus, the public member "list" loses its parameter of type String and becomes the raw type "List"
    The method "getN" loses its return type +"N extends Number"+ and yields simply a "Number".
    For a detailed discussion, see [http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#110257]

  • Timer Class in jsdk 1.4 w2000 doesn't compile

    Since this is based in the tutorial, shouldn't be a big deal but I spent the whole day looking for a solution. Please help!
    The tutorial presents this program:
    //1.3
    import java.util.timer;
    public class Problem {
    public static void main(String[] args) {
    final Timer timer = new Timer();
    timer.schedule(new TimerTask(), 5000);
    System.out.println("In 5 seconds this application will exit. ");
         public class TimerTask implements Timer {
    public void run() {
    System.out.println("Exiting.");
    timer.cancel();
    My problem starts because java.util doesn't have the timer class:
    Problem.java:2: Class java.util.timer not found in import.
    import java.util.timer;
    ^
    Now, JSDK 1.4 doesn't have timer as a package, but as a class, nevertheless, the instruction:
    import java.util.*; // instead of java.util.Timer
    doesn't compile because
    Problem.java:10: Interface Timer of inner class Problem. TimerTask not found.
    Problem.java:6: Class Timer not found in type declaration.
    I think Timer should be expressed as abstract, but how?
    I'm new in Java and feel a little frustrated...

    >
    ProblemSolved.java:3: Class java.util.Timer not found
    in import.
    import java.util.Timer;
    ^
    1 error
    Then you are not using java 1.3. You are using something before that.
    for the Timer and
    javac IteratorDemo.javaIteratorDemo.java:1: Interface java.util.Iterator of
    class IteratorDemo not foun
    d.
    public class IteratorDemo implements
    java.util.Iterator {
    ^
    1 error
    And this suggests that you are using something before 1.2.
    Just a thought...
    Windows comes with the MS version of java, which matches something like 1.1.6. It is in the path. So does you path put the jdk path first or last?

  • Vegastrike SVN - doesn't compile

    Hello everybody
    I have problem with vegastrike:
    http://aur.archlinux.org/packages.php?ID=16927
    It simply doesn't compile.
    ==> Setting up build environment...
    ==> Starting make...
    patching file boost/1_35/boost/mpl/apply.hpp
    patching file boost/1_35/boost/mpl/apply_wrap.hpp
    patching file boost/1_35/boost/mpl/aux_/full_lambda.hpp
    patching file boost/1_35/boost/mpl/aux_/numeric_op.hpp
    patching file boost/1_35/boost/mpl/bind.hpp
    patching file src/cmd/basecomputer.cpp
    Hunk #1 FAILED at 3142.
    1 out of 1 hunk FAILED -- saving rejects to file src/cmd/basecomputer.cpp.rej
    ==> BŁĄD: Budowanie nie powiodło się.
    src/cmd/basecomputer.cpp.rej says
    --- src/cmd/basecomputer.cpp 2009-07-17 20:59:40.166058029 +0200
    +++ src/cmd/basecomputer.cpp 2009-07-17 21:06:02.696008744 +0200
    @@ -3142,7 +3142,7 @@
    return s1.st_mtime - s2.st_mtime;
    -#if defined(_WIN32) && !defined(__CYGWIN__)
    +#if (__GLIBC__>2 || __GLIBC_MINOR__>=10) || (defined(_WIN32) && !defined(CYGWIN))
    typedef int (*scancompare) ( const struct dirent **v1, const struct dirent **v2 );
    #else
    typedef int (*scancompare) ( const void *v1, const void *v2 );
    Anybody?
    I have boost package installed.

    Yep - I have 0.5 package from arch-games repo, but I want SVN

  • Generated PLSQL doesn't compile

    I'm using OWB 10.2.0.1.0 with a client version of 10.2.0.1.31.
    In a mapping I'm using a constant with three outputs, first two are numeric and the third is a varchar2. When the plsql is generated it doesn't compile because the constant of type varchar2 isn't enclosed in single quotes.
    I'm new to OWB. Is this a documented problem. I can work around by enclosing the varchar2 constant with single quotes but if this is a problem and is fixed then I'll have to change all my constants that are character datatypes.
    Thanks
    Paddy

    Works great.
    My lack of knowledge, however on the generation I would have thought it not unreasonable for the UI to not allow literals to be entered without single quotes or in the code generation it would have recognised that this value is a datatype of char and create the quotes for it.
    Thanks
    Paddy

  • Delphi doesn't compile the examples for DIO32HS

    Delphi doesn't compile the examples for DIO32HS
    Some libraries appear to be required,
    but there are none supplied
    According to the manual, one ActiveX should be sufficient.
    What version is the source provided ?

    The NI CD is Version 6.9.2
    There are examples : \National Instruments\NI-DAQ\Examples\Delphi
    There is no mention which Version of Delphi,
    I have 3,5 and 6. However there should be components
    to be installed into Delphi as DigitalWaveformContinous
    requires TCWNumEdit, TCWDI and so on.
    It also requires the units CWUIControlsLib_TLB,
    CWAnalysisControlsLib_TLB, CWDAQControlsLib_TLB which are not part of Delphi istself but have to be provided
    by NI.
    Today I'm going to try Borland C++Builder, of which
    I have version 4 and 5. This will also require some
    components to be installed in BCB, I couldn't find them
    yet.
    \National Instruments\NI-DAQ\Examples\BorlandC
    BTW: this ActiveX that was talked about couldn't be
    found on the drive either. no *.ocx
    It cannot be that hard. I just want a procedure
    to setup the PCI-DIO-32HS, in terms of what is input
    and output, how the handshaking is done and then
    read/write to the port.
    Rene

  • Addes servlet.jar but still doesn't compile

    I'm building a servlet and therefor I added the servlet.jar file in my java/lib directory. After changing the classpath (adding the path to the lib directory), my servlet still doesn't compile. What could be wrong?
    debeumers

    to add a jar to the classpath, you must add the full path to the jar, for example java/lib/servlet.jar

  • Other Components Drawing Dashed Lines doesn't compile with Flex 4

    The lib was created in 2006 so it doesn't compile with Flex 4.
    The lib can be downloaded here http://www.quietlyscheming.com/blog/charts/dashed-lines/
    When compiling I get this error:
    Description     Resource     Path     Location     Type
    1136: Incorrect number of arguments.  Expected 3.     GraphicsUtils.as     /arrows/src/qs/utils     line 66     Flex Problem
    The line which doesn't compile:
    stroke.apply(target);
    How do I fix this error?

    I managed to compile the lib by rewriting the line:
    stroke.apply(target, new Rectangle(), new Point());
    But I don't understand what I have done.
    All Rectangle and Point dimensions are 0, but I'm sure it shouldn't be this way.

  • Generics won't compile

    hi all,
    have looked into the archives but this ridiculously basic problem I have hasn't come up...
    I am using 1.6 and have been for some time... things like NavigableMap work fine. For the first time today I tried to use a generic, and tried the simplest thing from the generics tutorial List<Integer> myIntList = new LinkedList<Integer>();
    I got the compilation error from the compiler saying "identifier expected" at the position of "<Integer>".
    Thought it might be the IDE so ran javac from the command line: same thing. Checked the version of javac: 1.6.0. Baffled... this is a Windows XP platform by the way.
    Mike

    Yes, the placing of the generic was wrong this time, sorry. With your test program, all alone, outside any package, the command line compiler worked!
    then I went back to my package file, SxwDoc.java, and that compiled with the CL! I'm happy, but have no idea why it didn't work before (when the generic was correctly placed).
    but the IDE (JBuilder 6) still doesn't work, and gives:
    "Test.java": Error #: 200 : <identifier> expected at line 4, column 7
    One of the project properties you have to set in JBuilder 6 is "Target VM"... you can choose "All Java SDKs", "Java 2 SDK v1.2 and later", "Java 2 SDK v1.3 and later" or "Java 2 SDK v1.4 and later".
    Could this conceivably be the problem? In which case I presume I'll have to upgrade to a more recent JBuilder (which I tried to do a few months ago but there was some problem).
    And yet, as I say, I have set the JDK under "Configure JDKs" to 1.6.0, and the IDE manages to compile things like NavigableMap...
    Thanks anyway!

  • Scriplet value in custom tag attribute doesn't compile

              Using a custom tag (a BodyTag extention) in a JSP. When WebLogic 6.0 tried to compile
              it I get the following error. It compiles fine in JBuilder and runs fine in resin
              servlet server.
              Here the source line from the JSP (I even put the messy spaces in the scriplet
              since that is how WebLogic examples do it):
              <tags:SystemSearch locationName="<%= locationName %>"     customerName="<%= customerName
              %>" systemModelNumber="<%= systemModelNumber %>"     systemName="<%= systemName %>"
              locationID="<%= locationID %>" >
              Here's the line of the compile error from the WebLogic generated servlet:
              tagsSystemSearch0.setLocationID weblogic.utils.StringUtils.valueOf("<%= locationID
              //[ /SystemBrowse.jsp; Line: 66]
              Here's the related error message:
              D:\java\bea\wlserver6.0\config\darcon\applications\.wl_temp_do_not_delete\WEB-INF\_tmp_war_dev1_dev1_ROOT\jsp_servlet\_systembrowse.java:202:
              unclosed string literal
              probably occurred due to an error in /SystemBrowse.jsp line 66:
              

    This is my tag code:
    public class ErrorTag extends SimpleTagSupport {
         private static final long serialVersionUID = 1L;
         String val = null;
         private static final String DIV = "<div class=\"error\">ERROR</div>";
         private static final String INSERT_HERE = "ERROR";
         public void doTag() throws JspException {
              try{
                   PageContext pageContext = (PageContext) getJspContext();
                  JspWriter out = pageContext.getOut();
                   if(val!=null){
                        String outputDiv = DIV.replace(INSERT_HERE, val);
                        out.println(outputDiv);
                        System.out.println("out.println -> ["+outputDiv+"]");
              }catch (Exception e) {
                   System.out.println("doStartTag -> ["+e.getMessage()+"]");
         public void setValue(Object value){
              System.out.println("setValue -> ["+value+"]");
              if(value!=null && value instanceof String){
                   String t = (String)value;
                   if(t.trim().length()>3){
                        val = t;
         public Object getValue(){
              return val;
    }I don't know waht to do. It doesn't want to eval EL expr.
    It produces output:
    *setValue -> [${errors.name}]*
    *out.println -> [<div class="error">${errors.name}</div>]*
    Edited by: Holod on 21.06.2009 15:12

  • Air for Ios doesn't compile actionscript

    Hi guys,
    I'm having a big problem... I'm developing a game to be published to web, ios, android. If I export the swf for the web or the apk for android everything is ok but when I try to package the swf using air for ios the swf doesn't contains any actionscript, the compilation is very fast and the swf is smaller, also if I try to debug the fla nothing happen because no code is compiled. This is started in the last two month, before I was able to package also to ios and I was able to create an ipa that I sent to apple store but now I need to modify the app and I can no more compile it. I have browsed the forum and read something about the umcompiled actionscript problem but I didn't load any external swf, I just use urlloader to load an xml and some images. I'm using flash cs5.5. Someone have some suggestion?

    If you are using Flash Professional.. I would just create a new FLA .. copy over your library assets, etc.   Make sure to point to your certificates and provisioning files, etc.. and recompile.
    Were you using an old version of AIR previously and have the new AIR SDK installed now ?
    I have found that compiling the IPA with ADT from the command line is much better than compiling from the IDE and allows you to use the iOS5.1 SDK instead of iOS4.

  • Cloog, doesn't compile

    Hello,
    Probably Mr. Allan is very busy and couldn't revise the package.
    The package doesn't success to compile, since it fails the isl check, as the comment already states. Unfortunately I'm not skilled to put hands on there.
    Here's the log
    Check file ./isl/jacobi-shared.cloog \c
    (options -f 4 -l -1 -override -strides 1 -sh 1 ), \c
    generating... \c
    --- cloog_temp 2015-01-10 18:43:09.655411045 +0100
    +++ ./isl/jacobi-shared.c 2013-10-11 09:27:03.000000000 +0200
    @@ -3,7 +3,7 @@
    if ((16*floord(t0-1,16) >= -N+g1+t0+1) && (16*floord(g1+t0-3,16) >= -N+g1+t0+1) && (32*floord(t1-1,32) >= -N+g2+t1+1) && (32*floord(g2+t1-3,32) >= t1-32)) {
    for (c0=max(-16*floord(t0-1,16)+t0,-16*floord(g1+t0-3,16)+t0);c0<=min(32,N-g1-1);c0+=16) {
    for (c1=-32*floord(t1-1,32)+t1;c1<=min(32,N-g2-1);c1+=32) {
    - if (c1 >= 1) {
    + if ((c1 >= 1) && (c1 <= 32)) {
    S1(c0+g1-1,c1+g2-1);
    FAIL: ./isl/jacobi-shared.c is not the same

    And do you have a line that looks like
    String currentText;anywhere?No just these three lines
    private String [] textString =
    {"Plain","Bold","Italic"};
    private JComboBox texts =new JComboBox(textString);
    texts.addItemListener(this);
    bingo. right there. that's what's wrong
    there's a lesson here: let your compiler tell you what's wrong, and believe it. it told you more or less exactly what was wrong, in pretty straightforward english, and is known to rarely lie :-)

  • [OCaml, lablgtk2, lablrsvg] My program doesn't compile (solved)

    Hi,
    I wrote few months ago (I used Ubuntu at that time, I just have installed ArchLinux one week ago) a little OCaml program which makes use of the lablgtk2 and lablrsvg libraries (OCaml bindings to gtk2 and rsvg).
    I installed ocaml and lablgtk2 (which normally contains lablrsvg, librsvg being flagged as a dependency), but when I try to compile, I get an error :
    $ ocamlc -w ys -I +lablgtk2 lablgtk.cma gtkInit.cmo lablrsvg.cma unix.cma entrelacs.cmo io.cmo entrelacs_IHM.ml -o Entrelacs
    File "entrelacs_IHM.ml", line 1, characters 0-1:
    Error: The file /usr/lib/ocaml/lablgtk2/lablrsvg.cma is not a bytecode object file
    make: *** [Entrelacs] Erreur 2
    The others files entrelacs.cmo and io.cmo doesn't need lablgtk2 (nor lablrsvg), and they compiled fine.
    In /usr/lib/ocaml/lablgtk2/, the file lablrsvg.cma exists, and `file' tells me that this is an "Objective caml library file (.cma) (Version 007)"
    The same program compiled fine when I used Ubuntu.
    What's wrong?
    Thank you
    (solved after the update of lablgtk2 today)
    Fractal
    Last edited by Fractal (2009-09-10 08:22:31)

    Things tend to move fasterYep... until something goes wrong... then you're completely stuffed, because you have no idea what's actually happening, because the idjit IDE is hiding all the gory details... it doesn't even tell you what it's doing, let alone how it's doing it, or what to do when it fails.
    Another argument for the command line is that it's simple. There are 16 distinct dialogues involved in adding a new jar to a library in jBuilder... There may well be less than 16 characters in the equivalent edition to the equivalent build command line. That's an extreme case, I admit, but it goes to disprove the notion that IDE's are simpler for noobs.
    Also, it's easier to get help on command line usage... because it's all text based you can just copy & paste the problematic command and it's output, and the eggspurts (tm) can do likewise with a response... and there are limited number of command lines out there... and *nix, windows, and mac cover maybe 99.5% of java users... and the eggspurts are likely to know all three (colectively if not as individuals) fairly well, because they deal with them all day every day.
    My belief is that noob's are better off at the command line until such time as they need (not just want to play with) a visual debugger... at which time its time to download netbeans and eclipse, and see which one suits you better... if you have money to splurge I'd also evaluate intelliJ... But avoid jBuilder, 2008 is total carp! The FREE eclipse is (IMHO) "nicer to use", and it has a LOT less bugs.
    Cheers. Keith.

  • Working with generics generates a compilation error

    hi again,
    i?m trying to work with generics but when i try to compile my work i get a "generics are not supported in -source 1.4" error, i am working with BlueJ, and i have jdk1.5.0_06 installed in my computer, why am i getting this error? is there any parameter I need to change in blueJ, if ti is so, Which one?
    thanks again...

    I actually think that the OP is compiling with Java 5, but he has set source compability to 1.4 on the project (or default settings). The error message "generics are not supported in -source 1.4" indicates the the compiler knows about generics.
    @OP. Look for something like source compability. I have never used BlueJ, but I would guess that you can find it under building/compiling, probably in some project settings.
    Kaj

Maybe you are looking for

  • XML Beans 1.0.4 parsing the response XML.

    Hi, I am reading an XML Document that was sent as a Stream from another Servlet using XMLBeans technology objectInputStream = new ObjectInputStream(new BufferedInputStream( postmethod.getResponseBodyAsaStream()); abcResponseDocument = ABCResponseDocu

  • Transaction isolation issue in 6.1

    How do I specify tx isolation in WebLogic 6.1 for local entities?           I've tried a stanza in weblogic-ejb-jar.xml like this:           <transaction-isolation>           <isolation-level>TRANSACTION_SERIALIZABLE</isolation-level>           <meth

  • Nano doesn't automatically start playing when connected to docking station

    I have a Philips CD/Radio/ipod player that is compatible with my nano. My husband has the a nano (same generation) and when he connects his to the docking station, it automatically starts playing. He can use the controls on the machine vs on the nano

  • Can't add APN after latest firmware upgrade for HTC One M8

    Hello Verizon device support. After the latest 4.4.3 firmware update there is no longer an option to add an APN! I travel overseas quite a bit and use pre-paid sim cards from various countries. Now it seems that vzw has coded the apn apk's to use an

  • Skip validation while opening modal panel

    Hi, I have a form where it got an icon to open an LOV(List Of Values) panel.The LOV panel is nothing but a modal panel. The original form(the parent form ) got couple of inputText with required="true" validation. To open the LOV panel i.e the modal p