Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7835825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:49:16+00:00 2026-06-02T13:49:16+00:00

Recently I have got a compilation error in the code below: import org.eclipse.swt.widgets.TreeItem; Object

  • 0

Recently I have got a compilation error in the code below:

import org.eclipse.swt.widgets.TreeItem;
Object parent; // can only be a Tree or a TreeItem    
...
TreeItem item = new TreeItem((parent instanceof TreeItem) ? (TreeItem) parent : (Tree) parent, SWT.NONE);

Compiler says: “The constructor TreeItem(Widget, int) is undefined”

Then I have tried it with another code:

Object x = new Integer(1);

Test t = new Test((x instanceof String) ? (String) x : (Integer) x);

class Test{
    public Test(String s){}
    public Test(Integer i){}
}

And got another error: “The constructor Test(Object&Serializable&Comparable) is undefined”

So I was forced to use the traditional if-else structure. Any ideas why the compiler behaves so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:49:26+00:00Added an answer on June 2, 2026 at 1:49 pm

    JLS §15.25 describes the ternary operator.

    Otherwise, the second and third operands are of types S1 and S2
    respectively. Let T1 be the type that results from applying boxing
    conversion to S1, and let T2 be the type that results from applying
    boxing conversion to S2.

    The type of the conditional expression is the result of applying
    capture conversion (§5.1.10) to lub(T1, T2) (§15.12.2.7).

    Basically, you can think of the ternary operator as a method: it can only have one “return type”. Since String and Integer are two different objects, it finds the common superclass and all interfaces implemented by both and creates a return type from that. (String and Integer both implement Serializable and Comparable and extend Object, so you get Object & Serializable & Comparable.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently got a new computer and I have put Eclipse Helios on
I have got an old site that has recently been displaying an error which
I have got the following problem with F# code recently: almost the complete code
I am programming in PHP mysql. I have recently got into OOP programming. So
I have got a strange problem about in_array recently which I cannot understand. e.g.
We have just recently got our SVN server installed. My developers have added the
I've been programming for many years and have just recently got the RoR itch.
I recently got into Java. I have a background in dynamic languages and I'm
I recently have a problem that my java code works perfectly ok on my
My main field is .Net but recently I have got something to do with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.