Skip to main content



      Home
Home » Newcomers » Newcomers » Avoid "The method ... can potentially be declared as static" warning
Avoid "The method ... can potentially be declared as static" warning [message #1435498] Wed, 01 October 2014 11:34 Go to next message
Eclipse UserFriend
How can I avoid the warning in this scenario?

public class A {
    // warning occurs on this method:
    // The method foo() from the type A can potentially be declared as static
    protected boolean foo() {
        return false;
    }
}

public final class B extends A {
    @Override
    protected boolean foo() {
        // do B specific things
    }
}
Re: Avoid "The method ... can potentially be declared as static" warning [message #1436076 is a reply to message #1435498] Thu, 02 October 2014 07:09 Go to previous messageGo to next message
Eclipse UserFriend
If you do not put the return in B.java has an error
(Sorry for bad english)

A.java
public class A {
	public boolean foo()
	{
		return false;
	}
}


B.java
public class B extends A {	
	@Override
	public boolean foo() {
		// TODO Auto-generated method stub
		return true;
	}
}

[Updated on: Thu, 02 October 2014 07:11] by Moderator

Re: Avoid "The method ... can potentially be declared as static" warning [message #1436157 is a reply to message #1435498] Thu, 02 October 2014 09:44 Go to previous messageGo to next message
Eclipse UserFriend
I was implying the return value with the comment. But better to be explicit about things.

public class A {
    // warning occurs on this method:
    // The method foo() from the type A can potentially be declared as static
    protected boolean foo() {
        return false;
    }
}

public final class B extends A {
    @Override
    protected boolean foo() {
        // do non-static, B specific things
        return true;
    }
}


The relevant Eclipse setting is here:
index.php/fa/19356/0/
  • Attachment: static.png
    (Size: 2.04KB, Downloaded 953 times)

[Updated on: Thu, 02 October 2014 09:44] by Moderator

Re: Avoid "The method ... can potentially be declared as static" warning [message #1436256 is a reply to message #1436157] Thu, 02 October 2014 12:21 Go to previous messageGo to next message
Eclipse UserFriend
That looks like a bug to me. The analysis that produces the warning should probably take into account the fact that the method is overridden by another class in the project (assuming B is in the same project as A). Try asking on the JDT forum, or just entering it into Bugzilla
Re: Avoid "The method ... can potentially be declared as static" warning [message #1436856 is a reply to message #1436256] Fri, 03 October 2014 10:02 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, I'll post it to JDT before entering a bug.
Re: Avoid "The method ... can potentially be declared as static" warning [message #1440515 is a reply to message #1436856] Wed, 08 October 2014 09:06 Go to previous message
Eclipse UserFriend
I get your question. I think the way things proceed is when we are in Class A there is no look at the function and see it is not accessing any other methods.

So let us narrow it's scope and make it static (so that it can only access static methods).

When we are in A we do not who is inheriting from A.
Previous Topic:Hide Header Row For Nested Table
Next Topic:Nanomind fail
Goto Forum:
  


Current Time: Thu Jul 03 19:38:01 EDT 2025

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

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

Back to the top