Bug 130017 - [1.5][compiler] @Override cannot be used for static methods
Summary: [1.5][compiler] @Override cannot be used for static methods
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-01 14:30 EST by Olivier Thomann CLA
Modified: 2006-08-09 06:01 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2006-03-01 14:30:51 EST
Since static methods can only be hidden and not overriden, @Override cannot be used for them.

The following code should report an error or at least a warning. Right we don't report anything.

class Base {
    public static void foo() {}
}

class Derived extends Base {
    @Override
    public static void foo() {}
}
Comment 1 Philipe Mulet CLA 2006-03-01 18:22:01 EST
Static methods should get complained indeed.
Introduced a new problem constant ID: IProblem#StaticMethodOverride

This is not a breaking API change, just an additional compiler diagnostic which we were missing incorrectly.
Comment 2 Philipe Mulet CLA 2006-03-01 18:24:06 EST
Mike/Jeff - slight API change, but still technically an API change. Can you pls cast your vote ? In the past, we did let new compiler IDs to make it until late in the game. Mostly JDT/UI is the only consumer for these so as to compute quickfixes (for a subset of them). 
Comment 3 Philipe Mulet CLA 2006-03-01 18:24:26 EST
cc'ing jeff
Comment 4 Philipe Mulet CLA 2006-03-01 18:25:42 EST
Can now tell:
	public static void foo() {}
	                   ^^^^^
The method foo() of type Derived cannot be tagged with @Override since it is static 
Comment 5 Philipe Mulet CLA 2006-03-01 18:29:47 EST
Hmm... actually, only saying:

The method foo() of type Derived must override a superclass method

wouldn't require any API change at all. Message is not as intuitive, though overriding only occurs in between instance methods; thus it is still accurate.
Comment 6 Philipe Mulet CLA 2006-03-01 18:44:19 EST
No need to worry Mike/Jeff. No more API change.

Fixed in HEAD.
Added AnnotationTest#test194.
Comment 7 David Audel CLA 2006-03-28 05:31:20 EST
Verified for 3.2 M6 using build I20060328-0010
Comment 8 Dani Megert CLA 2006-08-09 06:01:51 EDT
Could the message be improved for 3.3? See also thread "Problem with annotation" on eclipse.newcomer.