Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » eclipse does not insert @override annotation ?(does eclipse insert @override in codes for sub-classes automatically?)
eclipse does not insert @override annotation ? [message #1718074] Fri, 18 December 2015 22:50 Go to next message
Arthur Chan is currently offline Arthur ChanFriend
Messages: 44
Registered: September 2015
Member
Hi.

I read that eclipse automatically adds the @override annotation when in the sub-class, a method or object from the superclass is overridden.

I haven't seen this behaviour from eclipse, yet.

Maybe I was given wrong info?

Can someone point to sample codes please?

P.S.:

Here is a contrived example,
class Animal{
	public void move(){
		System.out.println("Animals can move.");
	}
	public void grow(){
		System.out.println("Animals can grow.");
	}
}

class Dog extends Animal{
	@Override       // <- I added this annotation, not eclipse 
	public void move(){
		System.out.println("Dogs can walk and run.");
	}
	public void bark(){
		System.out.println("Dogs can bark.");
	}
}



public class TestDog {

	public static void main(String[] args) {
		// 
		Animal a = new Animal(); 		
		Animal b = new Dog();			
		
		a.move();						
		b.move();						// executes the method in Dog class;
		b.grow();
		
	}

}


[Updated on: Fri, 18 December 2015 23:20]

Report message to a moderator

Re: eclipse does not insert @override annotation ? [message #1718265 is a reply to message #1718074] Mon, 21 December 2015 22:47 Go to previous messageGo to next message
Bernard Sarter is currently offline Bernard SarterFriend
Messages: 88
Registered: August 2011
Location: Paris, France
Member
Hi,

Eclipse can do it, for instance each time you save your file.

Have a look at Window => Preferences => Java => Editor => Save Actions, and check "Add missing @Override annotations'.

Hope that helps,
Bernard.
Re: eclipse does not insert @override annotation ? [message #1718332 is a reply to message #1718265] Tue, 22 December 2015 14:47 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3071
Registered: July 2009
Senior Member
Eclipse will also insert it automatically if you use Content Assist (code completion, Ctrl+Space) to insert the method body. For example, in your Dog class you could have typed "move" and then Ctrl+Space and Eclipse would offer to insert the overridden method, including the annotation.
Re: eclipse does not insert @override annotation ? [message #1718363 is a reply to message #1718332] Wed, 23 December 2015 00:16 Go to previous messageGo to next message
Arthur Chan is currently offline Arthur ChanFriend
Messages: 44
Registered: September 2015
Member
Thank-you for sharing,
Re: eclipse does not insert @override annotation ? [message #1718364 is a reply to message #1718265] Wed, 23 December 2015 00:18 Go to previous message
Arthur Chan is currently offline Arthur ChanFriend
Messages: 44
Registered: September 2015
Member
Yes, that works well. Thank you for sharing.
Previous Topic:Coming in COLD
Next Topic:eclipse line by line debugging
Goto Forum:
  


Current Time: Sun Oct 20 16:46:52 GMT 2019

Powered by FUDForum. Page generated in 0.02998 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top