2 Newbee questions

Discussion in 'Java' started by Christian, Feb 28, 2007.

  1. Christian

    Christian Guest

    Hello

    1. When I have an Class FooBar implementing the interfaces Foo and Bar

    if some other class has the two methods
    1. void doSomething(Foo foo) {}
    2. void doSomething(Bar bar) {}


    Which method will be called when I give an instance of FooBar as
    parameter? Where is the best place to search for answers on such
    questions maybe Language-Specifications?


    2. If I write a program that is made for opening some filetype, and I
    wan't only one instance of my program to be open i.e. open some tab in
    running instance myself when the user doubleclicks on a file ...

    Is there some easy solution to do this in java or do I need to create
    for example a tcp connection to my running instance and tell it the file
    parameter that way?

    Thanks for any Help
    C.O.
     
    Christian, Feb 28, 2007
    #1
    1. Advertising

  2. Re: 2 Newbie questions

    Hi,

    Christian wrote:
    > Hello
    >
    > 1. When I have an Class FooBar implementing the interfaces Foo and Bar
    >
    > if some other class has the two methods
    > 1. void doSomething(Foo foo) {}
    > 2. void doSomething(Bar bar) {}
    >
    > Which method will be called when I give an instance of FooBar as
    > parameter? Where is the best place to search for answers on such
    > questions maybe Language-Specifications?


    I think, *here* is a good place. Or perhaps better in c.l.j.help.

    The answer is: You will get a compiler-error, when trying
    doSomething(new FooBar()). Note that doSomething((Foo)new FooBar())
    should be possible, because the 'static type' (of the reference) is
    important, and not the 'dynamic type' (of the referenced Object).

    > 2. If I write a program that is made for opening some filetype, and I
    > wan't only one instance of my program to be open i.e. open some tab in
    > running instance myself when the user doubleclicks on a file ...
    >
    > Is there some easy solution to do this in java or do I need to create
    > for example a tcp connection to my running instance and tell it the file
    > parameter that way?


    No, a ServerSocket is the best solution. A lock-File is another solution
    but has obvious disadvantages.

    Hth,
    Ingo
     
    Ingo R. Homann, Feb 28, 2007
    #2
    1. Advertising

  3. Christian

    Guest

    Neither of them will be called because you can't complie it

    Christian wrote:
    > Hello
    >
    > 1. When I have an Class FooBar implementing the interfaces Foo and Bar
    >
    > if some other class has the two methods
    > 1. void doSomething(Foo foo) {}
    > 2. void doSomething(Bar bar) {}
    >
    >
    > Which method will be called when I give an instance of FooBar as
    > parameter? Where is the best place to search for answers on such
    > questions maybe Language-Specifications?
    >
    >
    > 2. If I write a program that is made for opening some filetype, and I
    > wan't only one instance of my program to be open i.e. open some tab in
    > running instance myself when the user doubleclicks on a file ...
    >
    > Is there some easy solution to do this in java or do I need to create
    > for example a tcp connection to my running instance and tell it the file
    > parameter that way?
    >
    > Thanks for any Help
    > C.O.
     
    , Mar 1, 2007
    #3
  4. Christian

    Chris Uppal Guest

    Christian wrote:

    > 1. When I have an Class FooBar implementing the interfaces Foo and Bar
    >
    > if some other class has the two methods
    > 1. void doSomething(Foo foo) {}
    > 2. void doSomething(Bar bar) {}
    >
    >
    > Which method will be called when I give an instance of FooBar as
    > parameter?


    The compiler should reject it as ambiguous, since there are two equally
    "suitable" candidate methods. To force it to choose one or the other you
    should use a cast, or a temporary variable of one or the other type.


    > Where is the best place to search for answers on such
    > questions maybe Language-Specifications?


    The JLS is indeed the place to look for such details. In this case you'd want
    section 15.12, Method Invocation Expressions. Be warned: that section is both
    long and complex.


    -- chris
     
    Chris Uppal, Mar 1, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Grober
    Replies:
    3
    Views:
    652
    Grober
    Dec 6, 2003
  2. Mohamed El Ashamwy
    Replies:
    0
    Views:
    381
    Mohamed El Ashamwy
    Dec 24, 2003
  3. DotNet
    Replies:
    5
    Views:
    398
    Kevin Spencer
    Jan 27, 2004
  4. vbGansta
    Replies:
    0
    Views:
    292
    vbGansta
    Feb 16, 2004
  5. Danny Ni

    newbee questions on web garden

    Danny Ni, Jul 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    375
    Robbe Morris [C# MVP]
    Jul 8, 2005
Loading...

Share This Page