在查看代码的某个时候,我看到许多方法都指定了注释:
@SuppressWarnings("unchecked")
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
在我的spring应用程序上下文文件中,我有类似的东西:
<util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.String">
<entry key="some_key" value="some value" />
<entry key="some_key_2" value="some value" />
</util:map>
Run Code Online (Sandbox Code Playgroud)
在java类中,实现如下:
private Map<String, String> someMap = new HashMap<String, String>();
someMap = (HashMap<String, String>)getApplicationContext().getBean("someMap");
Run Code Online (Sandbox Code Playgroud)
在Eclipse中,我看到一条警告说:
类型安全:从Object到HashMap的未选中转换
我做错了什么?我该如何解决这个问题?
当我选中一个复选框时,我希望它转向<p>
#0099ff
.
当我取消选中该复选框时,我希望它撤消该复选框.
我到目前为止的代码:
$('#checkbox').click(function(){
if ($('#checkbox').attr('checked')) {
/* NOT SURE WHAT TO DO HERE */
}
})
Run Code Online (Sandbox Code Playgroud) 如何<input type="checkbox" />
使用jQuery 捕获check/uncheck事件?
我在编译代码时收到一条消息:
Note: H:\Project2\MyGui2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Run Code Online (Sandbox Code Playgroud)
我该如何重新编译-Xlint:unchecked
?
int y = -2147483648;
int z = unchecked(y / -1);
Run Code Online (Sandbox Code Playgroud)
第二行引起了OverflowException
.不应该unchecked
阻止这个?
例如:
int y = -2147483648;
int z = unchecked(y * 2);
Run Code Online (Sandbox Code Playgroud)
不会导致例外.
我尝试将一个对象强制转换为我的Action类,但它会产生一个警告:
Type safety: Unchecked cast from Object to Action<ClientInterface>
Action<ClientInterface> action = null;
try {
Object o = c.newInstance();
if (o instanceof Action<?>) {
action = (Action<ClientInterface>) o;
} else {
// TODO 2 Auto-generated catch block
throw new InstantiationException();
}
[...]
Run Code Online (Sandbox Code Playgroud)
感谢您的任何帮助
@uncheckedVariance
可以用来弥合Scala的声明站点方差注释和Java的不变泛型之间的差距.
scala> import java.util.Comparator
import java.util.Comparator
scala> trait Foo[T] extends Comparator[T]
defined trait Foo
scala> trait Foo[-T] extends Comparator[T]
<console>:5: error: contravariant type T occurs in invariant position in type [-T]java.lang.Object with java.util.Comparator[T] of trait Foo
trait Foo[-T] extends Comparator[T]
^
scala> import annotation.unchecked._
import annotation.unchecked._
scala> trait Foo[-T] extends Comparator[T @uncheckedVariance]
defined trait Foo
Run Code Online (Sandbox Code Playgroud)
这表示java.util.Comparator自然是反变体,即类型参数T
出现在参数中,而不是返回类型.
这就引出了一个问题:为什么它还在Scala集合库中使用,它不是从Java接口扩展的?
trait GenericTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBuilder[A, CC[A] @uncheckedVariance]
Run Code Online (Sandbox Code Playgroud)
此注释的有效用途是什么?
我有以下Scala代码.
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 test = {
(Alice !? (100, "Hello")) match {
case i:Some[Int] => println ("Int received "+i)
case s:Some[String] => println ("String received "+s)
case _ =>
}
(Alice !? (100, 1)) match {
case i:Some[Int] => println ("Int received "+i)
case s:Some[String] => println ("String received …
Run Code Online (Sandbox Code Playgroud) 我想我得到了什么未经检查的演员意味着(从一个到另一个不同类型的演员),但是"检查"演员是什么意思?如何检查演员表以便我可以在Eclipse中避免此警告?