Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

2 Newbee questions

Thread view: 
Christian - 28 Feb 2007 15:56 GMT
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.
Ingo R. Homann - 28 Feb 2007 16:03 GMT
Hi,

> Hello
>
[quoted text clipped - 7 lines]
> 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
[quoted text clipped - 3 lines]
> 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
bearice@gmail.com - 01 Mar 2007 15:47 GMT
Neither of them will be called because you can't complie it

> Hello
>
[quoted text clipped - 18 lines]
> Thanks for any Help
> C.O.
Chris Uppal - 01 Mar 2007 17:12 GMT
> 1.  When I have an Class FooBar  implementing the interfaces Foo and Bar
>
[quoted text clipped - 4 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.