Skip to main content



      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 17:50 Go to next message
Eclipse UserFriend
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 18:20] by Moderator

Re: eclipse does not insert @override annotation ? [message #1718265 is a reply to message #1718074] Mon, 21 December 2015 17:47 Go to previous messageGo to next message
Eclipse UserFriend
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 09:47 Go to previous messageGo to next message
Eclipse UserFriend
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] Tue, 22 December 2015 19:16 Go to previous messageGo to next message
Eclipse UserFriend
Thank-you for sharing,
Re: eclipse does not insert @override annotation ? [message #1718364 is a reply to message #1718265] Tue, 22 December 2015 19:18 Go to previous message
Eclipse UserFriend
Yes, that works well. Thank you for sharing.
Previous Topic:Coming in COLD
Next Topic:eclipse line by line debugging
Goto Forum:
  


Current Time: Wed Jul 23 19:22:15 EDT 2025

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

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

Back to the top