Implementing an interface in eclipse

Discussion in 'Java' started by An Do, Mar 4, 2008.

  1. An Do

    An Do Guest

    Using IntelliJ, I would be able to implement an interface whilst having
    it open in the editor. You could open the context window using the
    keyboard and choose to implement interface and magically the
    implementation appears complete with the statement "... implements
    SomeInterface"

    Does anyone know how to do the same in eclipse so I don't have to open
    that New Class window and manually choose the interface?
     
    An Do, Mar 4, 2008
    #1
    1. Advertising

  2. An Do

    NeoGeoSNK Guest

    On Mar 4, 10:28 am, An Do <> wrote:
    > Using IntelliJ, I would be able to implement an interface whilst having
    > it open in the editor. You could open the context window using the
    > keyboard and choose to implement interface and magically the
    > implementation appears complete with the statement "... implements
    > SomeInterface"
    >
    > Does anyone know how to do the same in eclipse so I don't have to open
    > that New Class window and manually choose the interface?


    What do you mean about manually?
    you can right click the source file and select refactor -> Extract
    Interface...
    to implements an interface?
     
    NeoGeoSNK, Mar 4, 2008
    #2
    1. Advertising

  3. An Do

    An Do Guest

    NeoGeoSNK wrote:
    > On Mar 4, 10:28 am, An Do <> wrote:
    >> Using IntelliJ, I would be able to implement an interface whilst having
    >> it open in the editor. You could open the context window using the
    >> keyboard and choose to implement interface and magically the
    >> implementation appears complete with the statement "... implements
    >> SomeInterface"
    >>
    >> Does anyone know how to do the same in eclipse so I don't have to open
    >> that New Class window and manually choose the interface?

    >
    > What do you mean about manually?
    > you can right click the source file and select refactor -> Extract
    > Interface...
    > to implements an interface?


    Sorry I should explain a little more clearly. Let's say I have an
    interface "Foo". I want to create an implementation of that interface
    called "FooImpl". Using IntelliJ, all I would have to do is have my
    mouse in the editor window, open a context window and choose something
    like 'Implement Interface' and then it would automatically create
    "FooImpl".

    Is there a way of implementing an interface as quickly as this using
    Eclipse? Because as far as I have seen, you have to go do something
    like: New > Class > Type in 'FooImpl' > Choose an interface > Click Finish
     
    An Do, Mar 5, 2008
    #3
  4. An Do

    Peter Duniho Guest

    On Tue, 04 Mar 2008 22:14:25 -0800, An Do <>
    wrote:

    > [...]
    > Is there a way of implementing an interface as quickly as this using
    > Eclipse? Because as far as I have seen, you have to go do something
    > like: New > Class > Type in 'FooImpl' > Choose an interface > Click
    > Finish


    I can't compare with the IDE you're used to, not being familiar with it.
    But generally speaking, I use Eclipse's auto-implement functionality in
    one of two ways. Either I'm starting a new class from scratch, in which
    case I just add the interface(s) I intend to implement to the list in the
    dialog box for the new class, and then check the box that says to
    implement interfaces (this seems like the process you're talking about
    above). Or I'm adding an interface to a class, in which case after I've
    added the "implements XXX" to the class declaration, Eclipse will show a
    little error icon to the left of that line, which I can click and choose
    the "implement..." option.

    In either case, all the necessary stub methods for the interface will be
    added to the class, of which you can then of course replace the bodies
    with your own functionality.

    I don't know of any way to add a class to a project other than going
    through the "new class" dialog, but assuming one exists, it probably has a
    similar way to specify interfaces to implement. The fact that I'm not
    aware of the technique doesn't mean anything, really...I've only been
    using Eclipse for a few months.

    I don't really understand your description of how your other IDE does it
    though. You seemed to have left out steps for telling the IDE the name of
    your class and the name of the interface to implement, which account for
    half of the steps you describe as too much work in Eclipse. Maybe it's
    just because I don't know enough about your other IDE, but I don't really
    see how even the "long way" in Eclipse is that much work.

    Eclipse has a bunch of other ways to get at the refactoring features, and
    my guess is that if neither of those methods works for you, there's some
    other way that's more like what you're used to or more like what you
    want. I recommend just exploring a bit and see what's what.

    Pete
     
    Peter Duniho, Mar 5, 2008
    #4
  5. An Do

    An Do Guest

    Peter Duniho wrote:
    > On Tue, 04 Mar 2008 22:14:25 -0800, An Do <>
    > wrote:
    >
    >> [...]
    >> Is there a way of implementing an interface as quickly as this using
    >> Eclipse? Because as far as I have seen, you have to go do something
    >> like: New > Class > Type in 'FooImpl' > Choose an interface > Click
    >> Finish

    >
    > I can't compare with the IDE you're used to, not being familiar with
    > it. But generally speaking, I use Eclipse's auto-implement
    > functionality in one of two ways. Either I'm starting a new class from
    > scratch, in which case I just add the interface(s) I intend to implement
    > to the list in the dialog box for the new class, and then check the box
    > that says to implement interfaces (this seems like the process you're
    > talking about above). Or I'm adding an interface to a class, in which
    > case after I've added the "implements XXX" to the class declaration,
    > Eclipse will show a little error icon to the left of that line, which I
    > can click and choose the "implement..." option.
    >
    > In either case, all the necessary stub methods for the interface will be
    > added to the class, of which you can then of course replace the bodies
    > with your own functionality.
    >
    > I don't know of any way to add a class to a project other than going
    > through the "new class" dialog, but assuming one exists, it probably has
    > a similar way to specify interfaces to implement. The fact that I'm not
    > aware of the technique doesn't mean anything, really...I've only been
    > using Eclipse for a few months.
    >
    > I don't really understand your description of how your other IDE does it
    > though. You seemed to have left out steps for telling the IDE the name
    > of your class and the name of the interface to implement, which account
    > for half of the steps you describe as too much work in Eclipse. Maybe
    > it's just because I don't know enough about your other IDE, but I don't
    > really see how even the "long way" in Eclipse is that much work.
    >
    > Eclipse has a bunch of other ways to get at the refactoring features,
    > and my guess is that if neither of those methods works for you, there's
    > some other way that's more like what you're used to or more like what
    > you want. I recommend just exploring a bit and see what's what.
    >
    > Pete


    Thanks for the reply. Again it's probably hard to describe it unless I
    was just able to show you how I would do it in IntelliJ. But yes, I did
    miss the part where a dialog would come up and it would ask if you
    wanted to change the name of the implementation class. But it defaulted
    to FooImpl so you would just have to press enter. It's more the case
    that if you had an interface, you could hit ctl-enter to implement the
    class, then a dialog would come up asking if you wanted to change the
    default name and then you would hit enter again to accept FooImpl and
    that would be it.

    It's more the case that I could first create an interface and within one
    second, have a class implementing that interface. Whereas I have found
    it tedious in Eclipse having to create the interface and then having to
    move my mouse to the explorer pane, right click, choose new, type in the
    implementation class, find the interface I want the implementation to
    implement and then click ok. I guess I just wanted to know if Eclipse
    had a faster way to an implementation like IntelliJ as I was use to the
    speed and ease of not having to use the mouse at all and do it all in
    one second.

    thanks again.
     
    An Do, Mar 5, 2008
    #5
    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. Gomathi

    Implementing Interface

    Gomathi, Nov 17, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    557
    S.M. Altaf [MVP]
    Nov 17, 2005
  2. Manavendra Gupta
    Replies:
    1
    Views:
    360
    Manavendra Gupta
    Mar 7, 2004
  3. Robert Maas, see http://tinyurl.com/uh3t

    Trouble implementing an interface, strange compiler error

    Robert Maas, see http://tinyurl.com/uh3t, May 15, 2005, in forum: Java
    Replies:
    4
    Views:
    513
    Ross Bamford
    May 15, 2005
  4. golem
    Replies:
    13
    Views:
    789
    Nigel Wade
    Feb 17, 2006
  5. kscho
    Replies:
    1
    Views:
    396
    Rob Williscroft
    Sep 16, 2003
Loading...

Share This Page