草庐IT

unchecked-cast

全部标签

java - 如何使用 -Xlint :unchecked in a Maven project? 进行编译

在NetBeans7.2中,我无法找到如何在Maven项目中使用-Xlint:unchecked进行编译。在Ant项目下,您可以通过转到ProjectProperties->Compiling来更改编译器标志,但Maven项目似乎没有任何此类选项。有什么方法可以配置IDE以使用Maven使用此类标志进行编译? 最佳答案 我猜你可以在你的pom.xml中设置编译器参数。请引用http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-argu

java - 为什么混合 + 和 cast 不会在 "+(int)+(long)-1"中产生错误?

为什么会打印1?importjava.util.*;importjava.lang.*;importjava.io.*;classMain{publicstaticvoidmain(String[]args)throwsjava.lang.Exception{//yourcodegoeshereSystem.out.println((byte)+(short)-(int)+(long)-1);}}我们可以混合使用强制转换和+,-一元运算符吗?我知道我们可以进行多次强制转换,但为什么不将+,-一元运算符放在中间会产生错误? 最佳答案

java - 为什么混合 + 和 cast 不会在 "+(int)+(long)-1"中产生错误?

为什么会打印1?importjava.util.*;importjava.lang.*;importjava.io.*;classMain{publicstaticvoidmain(String[]args)throwsjava.lang.Exception{//yourcodegoeshereSystem.out.println((byte)+(short)-(int)+(long)-1);}}我们可以混合使用强制转换和+,-一元运算符吗?我知道我们可以进行多次强制转换,但为什么不将+,-一元运算符放在中间会产生错误? 最佳答案

Java Casting : Java 11 throws LambdaConversionException while 1. 8 没有

以下代码在Java1.8VM中运行良好,但在Java11VM中执行时会产生LambdaConversionException。区别在哪里,为什么会这样?代码:publicvoidaddSomeListener(Componentcomp){if(compinstanceofHasValue){((HasValue)comp).addValueChangeListener(evt->{//dosthwithevt});}}HasValueJavadoc异常(exception)(仅限V11):Causedby:java.lang.invoke.LambdaConversionExcept

Java Casting : Java 11 throws LambdaConversionException while 1. 8 没有

以下代码在Java1.8VM中运行良好,但在Java11VM中执行时会产生LambdaConversionException。区别在哪里,为什么会这样?代码:publicvoidaddSomeListener(Componentcomp){if(compinstanceofHasValue){((HasValue)comp).addValueChangeListener(evt->{//dosthwithevt});}}HasValueJavadoc异常(exception)(仅限V11):Causedby:java.lang.invoke.LambdaConversionExcept

c++ - 'reinterpret_cast' : cannot convert from 'overloaded-function' to 'intptr_t' with boost. dll

我正在使用Boost.dll开发插件系统#include#include#includeclassbase{public:base(){};~base(){};templatestaticstd::shared_ptrcreate(){returnstd::make_shared();}virtualvoiddo1()=0;};classderived:publicbase{public:derived(){};~derived(){};virtualvoiddo1()override{}};BOOST_DLL_ALIAS(base::create,//();当我尝试在BOOST_DL

c++ - static_cast 没有按预期处理优先级

#include#includetemplatevoidfoo(){std::coutvoidfoo(){std::cout(42)>();foo(42)>();return(0);}知道为什么这没有按预期工作吗?我的gcc4.8.1提示调用不明确,但static_cast不应该在这种情况下“修复”优先规则,在这种情况下您有2种具有相同优先级的类型? 最佳答案 您可能认为编译器在解析重载函数模板时会尝试找出哪个模板与给定参数更匹配。基于该假设,带有uint8_t的模板应该比带有int的模板更好地匹配带有uint8_t参数的函数调用。

ios - LLDB( swift ): Casting Raw Address into Usable Type

是否有LLDB命令可以将原始地址转换为可用的Swift类?例如:(lldb)po0x7df67c50asMKPinAnnotationView我知道这个地址指向一个MKPinAnnotationView,但它不在我可以选择的框架中。但是,我想将原始地址转换为MKPinAnnotationView,以便我可以检查它的属性。这可能吗? 最佳答案 在Xcode8.2.1和Swift3下,lldb命令po或p将不起作用与类型变量。您将需要使用快速命令print来检查类型化对象实例的属性。(感谢cbowns'sanswer!)例如:expr-

c# - InvalidCastException : Unable To Cast Objects of type [base] to type [subclass]

我有一个继承自MembershipUser的自定义CustomMembershipUser。publicclassConfigMembershipUser:MembershipUser{//customstuff}我正在使用Linq-to-SQL从数据库中读取并获取用户实体;为了使此功能成为MembershipUser,我定义了一个显式转换:publicstaticexplicitoperatorMembershipUser(Useruser){DateTimenow=DateTime.Now;if(user==null)returnnull;returnnewMembershipUs

kotlin - 处理这种情况的最佳方法是 "smart cast is imposible"

我想知道处理这种情况的最佳方法是什么classPerson(varname:String?=null,varage:Int?=null){funtest(){if(name!=null&&age!=null)doSth(name,age)//smartcastimposible}fundoSth(someValue:String,someValue2:Int){}}调用doSth方法并确保name和age为ntnull的最简单方法是什么?我正在寻找一些简单的东西,比如我会简单地使用let的可变场景name?.let{doSth(it)} 最佳答案