RFC: draft API for JEP 269 Convenience Collection Factories
Timo Kinnunen
timo.kinnunen at gmail.com
Mon Oct 19 15:17:34 UTC 2015
They are warnings in Eclipse and IntelliJ IDEA:
“The static method foo() from the type A should be accessed directly”
“The static method foo() from the type A should be accessed in a static way”
“The static method foo() from the type A should be accessed directly”
“Static method 'foo()' declared in class 'test.A' but referenced via subclass”
“Static member 'test.A.foo()' accessed via instance reference”
“Static member 'test.B.foo()' accessed via instance reference”
Neither one has the warning for B.foo() enabled by default but provide it under their “potential problems” categories.
Sent from Mail for Windows 10
From: Stuart Marks
Sent: Monday, October 19, 2015 03:13
To: joe darcy;Andrew Haley
Cc: core-libs-dev
Subject: Re: RFC: draft API for JEP 269 Convenience Collection Factories
On 10/18/15 10:45 AM, joe darcy wrote:
> On 10/17/2015 10:10 AM, Andrew Haley wrote:
>> On 10/17/2015 05:46 PM, Stuart Marks wrote:
>>> (I view calling an "inherited" class static method to be poor coding style, but
>>> neither javac nor NetBeans warns about it.)
>> That surely can be fixed. Should we start a feature request?
>
> I believe
>
> javac -Xlint:static ...
>
> does the check of interest; from running javac -X
>
> static Warn about accessing a static member using an instance
Nope, it doesn't, I was surprised too.
class A {
static void foo() {
System.out.println("A.foo()");
}
}
class B extends A {
}
B.foo(); // no warning
A a = new A();
a.foo(); // warning
B b = new B();
b.foo(); // warning
I've filed
https://bugs.openjdk.java.net/browse/JDK-8139827
I checked NetBeans but I only looked briefly at the hints and style options, and
nothing I enabled generated a warning. But it would probably be worth it for
someone to take another look. It would also be helpful if somebody could check
this with other IDEs as well.
s'marks
More information about the core-libs-dev
mailing list