Announcement Announcement Module
No announcement yet.
Java @Override methods compile well with Maven but not with STS Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java @Override methods compile well with Maven but not with STS

    Hello Guys

    I did realize the follow

    I could have the follow code (I am using a similar code taken from a tutorial with the same structure)

    package com.manuel.jordan;
    public class ManuelThread implements Runnable {
    	 public void run() {
    This code with Maven 2.2.1 and JDK 6 - 21, compile well

    ....> mvn clean compile
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building channels
    [INFO]    task-segment: [clean, compile]
    [INFO] ------------------------------------------------------------------------
    [INFO] [clean:clean {execution: default-clean}]
    [INFO] Deleting directory ....\target
    [INFO] [resources:resources {execution: default-resources}]
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 8 resources
    [INFO] [compiler:compile {execution: default-compile}]
    [INFO] Compiling 27 source files to .....\target\classes
    [INFO] ------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 2 seconds
    [INFO] Finished at: Thu Jul 14 12:09:54 COT 2011
    [INFO] Final Memory: 12M/30M
    [INFO] ------------------------------------------------------------------------
    Did realize yourself, none warning or something related is shown above

    But the same java code shown above opened in STS 2.6.1 or with STS 2.7.0 and using the same JDK 6 - 21, I got the follow error when the editor is open.

    Multiple markers at this line
    	- implements
    	- The method run() of type ManuelThread must override a superclass method
    To avoid this, is mandatory commenting the annotation

    public void run() {
    Why this behavior?, I know @Override should be used only in inheritance of classes.

    But since I am using my code which is similar from a code taken from a tutorial with the same structure, I just did realize this situation working with STS, where this @Override is being applied with an Interface

    Of course could be illogic apply this approach working with interfaces, but in Google I did realize that in many tutorials (not all) the same approach is used above.

    Furthermore this same error situation appear if I use for example the follow code

    jmsTemplate.send(new MessageCreator() {
           public javax.jms.Message createMessage(Session session) throws JMSException {
    	    MapMessage message = session.createMapMessage();
    			"Sending message: " + message);
    	    return message;
    Where MessageCreator is an interface, see the API here

    Yes a Interface and working with new

    Anyway with STS I got

    Multiple markers at this line
    	- The method createMessage(Session) of type new MessageCreator(){} 
              must override a superclass method
    	- implements org.springframework.jms.core.MessageCreator.createMessage
    How I can handle this?, I need the code totally portable to work with and without STS

    Thanks in advanced

  • #2
    Configure your project as a jdk 1.6 project (set the compiler level) -> Project -> Properties -> Java Compiler... Or include the compiler plugin in your maven pom anx explicitly set the compiler to 1.6 and then let the maven tooling update the properties.

    					<!-- -->
    After that right click on the project -> Maven -> Update Project Configuration...


    • #3
      Thank You

      Hello Marten

      Thanks a lot, both approaches work well!

      I tested in STS 2.6.1 and STS 2.7.0, practically the first affects to all the projects, I tried the second which work fine with Maven alone, but for the IDE I did the same but I didnt realize about the extra step working with the IDE

      After that right click on the project -> Maven -> Update Project Configuration...
      I checked in Google about this new behaviour about the @Override annotation applied for Interfaces which only work for JDK 6, wondered why not exists an explicit annotation to do a real comparison about @Override about inheritance of classes and other like @Implement for interfaces. Perhaps JDK 7 offer this

      For other members something about this in these threads

      When do you use Java's @Override annotation and why?
      @Override specification changes in Java 6

      Thanks again Marten!