Warn About Raw Types?

  • Thread starter Lawrence D'Oliveiro
  • Start date
L

Lawrence D'Oliveiro

I was setting up a table of tabs for a tabbed activity in Android. The
initial part of my table entry definition looks like this:

class TabParams
{
String Name;
String Title;
int IconID;
Class FrameClass;

Compiled and ran just fine. Then I noticed that “Class†is being used as a
raw type. So I changed that last line to

Class<? extends android.app.Activity> FrameClass;

There doesn’t seem to be any option in javac to warn about this sort of
thing.
 
D

Daniele Futtorovic

I was setting up a table of tabs for a tabbed activity in Android. The
initial part of my table entry definition looks like this:

class TabParams
{
String Name;
String Title;
int IconID;
Class FrameClass;

Compiled and ran just fine. Then I noticed that “Class” is being used as a
raw type. So I changed that last line to

Class<? extends android.app.Activity> FrameClass;

There doesn’t seem to be any option in javac to warn about this sort of
thing.

Epic fail.
 
S

Stanimir Stamenkov

Mon, 14 Feb 2011 12:21:34 +1300, /Lawrence D'Oliveiro/:
Compiled and ran just fine. Then I noticed that “Class†is being used as a
raw type. So I changed that last line to

Class<? extends android.app.Activity> FrameClass;

There doesn’t seem to be any option in javac to warn about this sort of
thing.

Have you tried:

% javac
Usage: javac <options> <source files>
where possible options include:
...
-X Print a synopsis of nonstandard options

% javac -X
-Xlint Enable recommended warnings
-Xlint:{all,cast,deprecation,divzero,empty,unchecked,fallthrough,path,serial,finally,overrides,-cast,-deprecation,-divzero,-empty,
-unchecked,-fallthrough,-path,-serial,-finally,-overrides,none}Enable or disable specific warnings
...
 
M

markspace

I was setting up a table of tabs for a tabbed activity in Android. The
initial part of my table entry definition looks like this:

class TabParams
{
String Name;
String Title;
int IconID;
Class FrameClass;

Compiled and ran just fine. Then I noticed that “Class†is being used as a
raw type. So I changed that last line to

Class<? extends android.app.Activity> FrameClass;

There doesn’t seem to be any option in javac to warn about this sort of
thing.


Try this:

<http://lmgtfy.com/?q=javac+raw+type>


Third one down on my results list.
 
L

Lawrence D'Oliveiro

Mon, 14 Feb 2011 12:21:34 +1300, /Lawrence D'Oliveiro/:


Have you tried:

% javac
Usage: javac <options> <source files>
where possible options include:
...
-X Print a synopsis of nonstandard options

% javac -X
-Xlint Enable recommended warnings
-Xlint:{all,cast,deprecation,divzero,empty,unchecked,fallthrough,path,serial,finally,overrides,-cast,-deprecation,-divzero,-empty,
-unchecked,-fallthrough,-path,-serial,-finally,-overrides,none}Enable or
disable specific warnings

ldo@theon:java_try> cat test.java
class test
{
public static void main(String[] args)
{
Class s = String.class;
} /*main*/
}
ldo@theon:java_try> javac -Xlint test.java
ldo@theon:java_try> javac -Xlint:deprecation test.java
ldo@theon:java_try> javac -Xlint:all test.java
ldo@theon:java_try>

No warnings.

Any other suggestions?
 
M

markspace

ldo@theon:java_try> javac -Xlint test.java
ldo@theon:java_try> javac -Xlint:all test.java
ldo@theon:java_try>

No warnings.

Any other suggestions?


I gotta admit, I thought these would work. There's some documentation
on the web that seems to indicate it should. But it didn't work for me
either.
 
L

Lawrence D'Oliveiro

I gotta admit, I thought these would work.

Yeah, all these fucking stupid idiots shooting their mouth off as though
they really knew something I didn’t...
 
A

Arved Sandstrom

I gotta admit, I thought these would work. There's some documentation on
the web that seems to indicate it should. But it didn't work for me either.
Another useful article:
http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types. Somewhat
dated but I think still largely relevant to this discussion.

It's perhaps worth noting that if working inside Eclipse that the IDE
will flag certain raw type usages that are labelled as "harmless" in
that article (Preferences / Java / Compiler / Errors and Warnings /
Generic types / Usage of a raw type)

Pursuant to the article above I think it's actually JDK 7 that
introduces the -Xlint:rawtypes option. With OpenJDK 6 or Sun jdk 6 you'd
just have to be somewhat knowledgeable about what you're doing...tall
order for some characters no doubt.

AHS
 
L

Lew

Arved said:
Another useful article:
http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types. Somewhat dated
but I think still largely relevant to this discussion.

It's perhaps worth noting that if working inside Eclipse that the IDE will
flag certain raw type usages that are labelled as "harmless" in that article
(Preferences / Java / Compiler / Errors and Warnings / Generic types / Usage
of a raw type)

Pursuant to the article above I think it's actually JDK 7 that introduces the
-Xlint:rawtypes option. With OpenJDK 6 or Sun jdk 6 you'd just have to be
somewhat knowledgeable about what you're doing...tall order for some
characters no doubt.

God forbid that we should require programmers to be somewhat knowledgeable
about what they're doing!

Every time that's suggested in this group you get a lot of squeaky pushback.
"Oh, you're just a JLS lawyer!" (Is that a bad thing?) "No one should be
expected to know the entire 'String' interface!" "The ternary operator is too
confusing!" (And that's just from people who know what "ternary operator"
means - the usual complaint is, "The question-mark operator is too
confusing!") "I don't really need to synchronize access, do I?" "What's an
API doc?"
 
M

markspace

Yeah, all these fucking stupid idiots shooting their mouth off as though
they really knew something I didn’t...


To be fair to them, the last three posts you've made in this forum were
pretty fucking retarded. I guess everyone just assumed that the fucking
retard boy was just crying fucking wolf again.

In other news, even a broken clock is right twice a day.
 
R

Roedy Green

There doesn’t seem to be any option in javac to warn about this sort of
thing.

Do you have your target set to prior to 1.5? If so, it will not
complain. Are you using ordinary javac with android or some special
java in an a IDE?
--
Roedy Green Canadian Mind Products
http://mindprod.com
Refactor early. If you procrastinate, you will have
even more code to adjust based on the faulty design.
..
 
L

Lawrence D'Oliveiro

Do you have your target set to prior to 1.5?

From my javac(1) man page:

The default for -target depends on the value of -source:

o If -source is not specified, the value of -target is 1.6
Are you using ordinary javac with android or some special java in an a
IDE?

The example I posted elsewhere used the javac command with no options
whatsoever.
 
S

Stanimir Stamenkov

Mon, 14 Feb 2011 14:06:35 +1300, /Lawrence D'Oliveiro/:
ldo@theon:java_try> cat test.java
class test
{
public static void main(String[] args)
{
Class s = String.class;
} /*main*/
}
ldo@theon:java_try> javac -Xlint test.java
ldo@theon:java_try> javac -Xlint:deprecation test.java
ldo@theon:java_try> javac -Xlint:all test.java
ldo@theon:java_try>

No warnings.

Any other suggestions?

Trying an example from the "lmgtfy" results [1] given in a reply by
markspace:

import java.util.*;
class test {
public static void main(String[] args) {
ArrayList data = new ArrayList();
data.add("hello");
data.add("world");

Iterator<String> it = data.iterator();
while (it.hasNext()) {
String s = it.next();
System.out.println(s);
}
}
}

I get:

% javac test.java
Note: test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

% javac test.java -Xlint
test.java:5: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
data.add("hello");
^
test.java:6: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
data.add("world");
^
test.java:9: warning: [unchecked] unchecked conversion
found : java.util.Iterator
required: java.util.Iterator<java.lang.String>
Iterator<String> it = data.iterator();
^
3 warnings

It appears your exact example doesn't make javac emit "unchecked"
warning, while I can see such warning in my Eclipse IDE. It could
be related to the "harmless" nature of your example, as indicated
in the Arved Sandstrom's reply.

[1] http://www.rgagnon.com/javadetails/java-0521.html
 
R

Roedy Green

The example I posted elsewhere used the javac command with no options
whatsoever.

there are lots of programs called Javac floating about the universe.
Just in case, get it to identify itself with javac -version.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Refactor early. If you procrastinate, you will have
even more code to adjust based on the faulty design.
..
 
L

Lawrence D'Oliveiro

there are lots of programs called Javac floating about the universe.
Just in case, get it to identify itself with javac -version.

ldo@theon:~> javac -version
javac 1.6.0_22

also:

ldo@theon:~> dpkg-query -S $(readlink -f $(which javac))
sun-java6-jdk: /usr/lib/jvm/java-6-sun-1.6.0.22/bin/javac
 
L

Lawrence D'Oliveiro

Stanimir Stamenkov said:
It appears your exact example doesn't make javac emit "unchecked"
warning, while I can see such warning in my Eclipse IDE. It could
be related to the "harmless" nature of your example ...

If it’s “harmlessâ€, then why is there a warning against it in bold type on
page 58 of the Java Language Spec?

<http://groups.google.com/[email protected]>
 
A

Arne Vajhøj

God forbid that we should require programmers to be somewhat
knowledgeable about what they're doing!

Every time that's suggested in this group you get a lot of squeaky
pushback. "Oh, you're just a JLS lawyer!" (Is that a bad thing?) "No one
should be expected to know the entire 'String' interface!" "The ternary
operator is too confusing!" (And that's just from people who know what
"ternary operator" means - the usual complaint is, "The question-mark
operator is too confusing!") "I don't really need to synchronize access,
do I?" "What's an API doc?"

Knowing the more common parts of the Java API and be able to
look up the rest very quickly is invaluable for a Java developer.

I am more skeptical about studying the JLS. If the code requires
JLS studying to figure out what it does or whether it is good, then
it should be rewritten to something more maintainable.

And I think it is much better to call it the ?: operator, because
ternary operator is a general term that just happen to identify
the operator by the fact that Java currently only have one
ternary operator.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top