Questions tagged [unchecked]

An option "unchecked" used to turn off a javac compiler warnings about failing to use generics because it does not have enough type information to perform all type checks necessary to ensure type safety.

The term "unchecked" means that the javac compiler does not have enough type information to perform all type checks necessary to ensure type safety. The "unchecked" warning is disabled, by default, though the compiler gives a hint. To see all "unchecked" warnings, recompile with -Xlint:unchecked.

In JDK 1.5 an annotation was introduced called SuppressWarnings. It could be used to insert the annotation prior to a class or method telling which sort of warning you want suppressed.

A @SuppressWarning option unchecked used to turn off a javac compiler warnings about failing to use generics.

234 questions
468
votes
11 answers

What is SuppressWarnings ("unchecked") in Java?

Sometime when looking through code, I see many methods specify an annotation: @SuppressWarnings("unchecked") What does this mean?
jojo
  • 12,563
  • 30
  • 82
  • 119
292
votes
10 answers

Type safety: Unchecked cast

In my spring application context file, I have something like:
DragonBorn
  • 9,603
  • 10
  • 35
  • 47
128
votes
9 answers

Catch checked change event of a checkbox

How do I to catch check/uncheck event of with jQuery?
omg
  • 123,990
  • 135
  • 275
  • 341
127
votes
11 answers

if checkbox is checked, do this

When I check a checkbox, I want it to turn

#0099ff. When I uncheck the checkbox, I want it to undo that. Code I have so far: $('#checkbox').click(function(){ if ($('#checkbox').attr('checked')) { /* NOT SURE WHAT TO DO HERE */ …

android.nick
  • 10,260
  • 22
  • 70
  • 111
89
votes
11 answers

How do I compile with -Xlint:unchecked?

I'm getting a message when I compile my code: Note: H:\Project2\MyGui2.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. How do I recompile with -Xlint:unchecked?
Dave Fisher
  • 985
  • 2
  • 8
  • 10
47
votes
3 answers

Why dividing int.MinValue by -1 threw OverflowException in unchecked context?

int y = -2147483648; int z = unchecked(y / -1); The second line causes an OverflowException. Shouldn't unchecked prevent this? For example: int y = -2147483648; int z = unchecked(y * 2); doesn't cause an exception.
46
votes
6 answers

Type safety: Unchecked cast from Object

I try to cast an object to my Action class, but it results in a warning: Type safety: Unchecked cast from Object to Action Action action = null; try { Object o = c.newInstance(); if (o instanceof Action) { …
Matthew
  • 9,868
  • 7
  • 48
  • 64
40
votes
3 answers

When is @uncheckedVariance needed in Scala, and why is it used in GenericTraversableTemplate?

@uncheckedVariance can be used to bridge the gap between Scala's declaration site variance annotations and Java's invariant generics. scala> import java.util.Comparator import java.util.Comparator scala> trait Foo[T] extends…
retronym
  • 53,652
  • 11
  • 151
  • 168
36
votes
2 answers

Unchecked assignment warning

I am using Android Studio 1.1.0. This causes no warning: public static class A { public Map getMap() { return null; } } public static class B { public void processA(A a) { Map map =…
Konrad Morawski
  • 7,689
  • 6
  • 47
  • 80
34
votes
3 answers

Scala pattern matching confusion with Option[Any]

I have the following Scala code. import scala.actors.Actor object Alice extends Actor { this.start def act{ loop{ react { case "Hello" => sender ! "Hi" case i:Int => sender ! 0 } } } } object Test { def…
Jus12
  • 17,058
  • 25
  • 90
  • 151
32
votes
3 answers

What is unchecked cast and how do I check it?

I think I get what unchecked cast means (casting from one to another of a different type), but what does it mean to "Check" the cast? How can I check the cast so that I can avoid this warning in Eclipse?
SIr Codealot
  • 4,843
  • 8
  • 31
  • 44
24
votes
3 answers

Java "unchecked call to compareTo(T) as a member of the raw type java.lang.Comparable"

I'm trying to implement a sorted list as a simple exercise in Java. To make it generic I have an add(Comparable obj) so I can use it with any class that implements the Comparable interface. But, when I use obj.compareTo(...) anywhere in the code I…
3mpty
  • 476
  • 1
  • 5
  • 14
21
votes
4 answers

Why is SQLException a checked exception

Can anyone think of a rational reason why SQLException is a checked exception? Yes, there could be a syntax error in the query Yes, the connection might have died Yes, there might be a permission problem Etc, etc blah blah blah But practically 100%…
Bohemian
  • 365,064
  • 84
  • 522
  • 658
19
votes
4 answers

IntelliJ says "Warning: java: foo/bar/Baz.java uses unchecked or unsafe operations", but it doesn't say in which line it is referring to

I am getting this warning: When I click on the image, it just opens the associated Editor, but it doesn't say the line number where the warning is raised. I don't want to add @SuppressWarning("unchecked") on the whole class... Any workaround/fix?
18
votes
5 answers

Checked vs. Unchecked Exceptions in Service Layer

I work on a project with a legacy service layer that returns null in many places if a requested record does not exist, or cannot be accessed due to the caller not being authorized. I am talking about specific records requested by ID. For instance,…
S73417H
  • 2,551
  • 2
  • 21
  • 36
1
2 3
15 16