Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 15:34 Go to next message
Andrew C is currently offline Andrew CFriend
Messages: 6
Registered: October 2014
Junior Member
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 11:09 Go to previous messageGo to next message
Eduardo Savoine is currently offline Eduardo SavoineFriend
Messages: 2
Registered: October 2014
Junior Member
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 11:11]

Report message to a moderator

Re: Avoid "The method ... can potentially be declared as static" warning [message #1436157 is a reply to message #1435498] Thu, 02 October 2014 13:44 Go to previous messageGo to next message
Andrew C is currently offline Andrew CFriend
Messages: 6
Registered: October 2014
Junior Member
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 524 times)

[Updated on: Thu, 02 October 2014 13:44]

Report message to a moderator

Re: Avoid "The method ... can potentially be declared as static" warning [message #1436256 is a reply to message #1436157] Thu, 02 October 2014 16:21 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3071
Registered: July 2009
Senior Member
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 14:02 Go to previous messageGo to next message
Andrew C is currently offline Andrew CFriend
Messages: 6
Registered: October 2014
Junior Member
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 13:06 Go to previous message
shankha banerjee is currently offline shankha banerjeeFriend
Messages: 40
Registered: February 2013
Member
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: Tue Oct 15 01:05:09 GMT 2019

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

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

Back to the top