草庐IT

unchecked-cast

全部标签

为什么C ++编译器不从最后一类优化此Dynamic_cast?

考虑此类层次结构:structAnimal{virtual~Animal();};structCat:virtualAnimal{};structDogfinal:virtualAnimal{};我的理解是final上classDog确保没有人可以创建从Dog,这是必然的,这意味着没有人可以创建一个is-a的班级Dog和is-aCat同时。考虑这两个dynamic_castS:Dog*to_final(Cat*c){returndynamic_cast(c);}Cat*from_final(Dog*d){returndynamic_cast(d);}GCC,ICC和MSVC忽略final预选赛

java:如何修复 Unchecked cast 警告

我有以下代码:privateHashMap,HashMap>m_componentStores;publicTgetComponent(Entitye,ClassexampleClass){HashMapstore=m_componentStores.get(exampleClass);Tresult=(T)store.get(e);if(result==null){thrownewIllegalArgumentException("GETFAIL:"+e+"doesnotpossessComponentofclass\nmissing:"+exampleClass);}returnr

java:如何修复 Unchecked cast 警告

我有以下代码:privateHashMap,HashMap>m_componentStores;publicTgetComponent(Entitye,ClassexampleClass){HashMapstore=m_componentStores.get(exampleClass);Tresult=(T)store.get(e);if(result==null){thrownewIllegalArgumentException("GETFAIL:"+e+"doesnotpossessComponentofclass\nmissing:"+exampleClass);}returnr

java - 如何在 Java 中使用 double to int cast

我是Java新手,想知道doubletointcast是如何工作的?我知道通过取低32位来long到int很简单,但是double(64位)到int(32位)呢?二进制中double的那些64位是double浮点格式(尾数),那么它如何在内部转换为int呢? 最佳答案 全部记录在section5.1.3中JLS.Inthefirststep,thefloating-pointnumberisconvertedeithertoalong,ifTislong,ortoanint,ifTisbyte,short,char,orint,as

java - 如何在 Java 中使用 double to int cast

我是Java新手,想知道doubletointcast是如何工作的?我知道通过取低32位来long到int很简单,但是double(64位)到int(32位)呢?二进制中double的那些64位是double浮点格式(尾数),那么它如何在内部转换为int呢? 最佳答案 全部记录在section5.1.3中JLS.Inthefirststep,thefloating-pointnumberisconvertedeithertoalong,ifTislong,ortoanint,ifTisbyte,short,char,orint,as

使用 vector 的 Java 警告 : unchecked call to add(E)

有问题的代码Vectormoves=newVector();moves.add(newInteger(x));错误:ConnectFour.java:82:warning:[unchecked]uncheckedcalltoadd(E)asamemberoftherawtypejava.util.Vectormoves.add(newInteger(x));不太确定这样的错误需要多少信息...... 最佳答案 问题是上面的代码没有使用generics.以下将起作用:Vectormoves=newVector();move.add(n

使用 vector 的 Java 警告 : unchecked call to add(E)

有问题的代码Vectormoves=newVector();moves.add(newInteger(x));错误:ConnectFour.java:82:warning:[unchecked]uncheckedcalltoadd(E)asamemberoftherawtypejava.util.Vectormoves.add(newInteger(x));不太确定这样的错误需要多少信息...... 最佳答案 问题是上面的代码没有使用generics.以下将起作用:Vectormoves=newVector();move.add(n

java - 在 Java 中,int cast 的工作时间有多长?

这个问题不是关于longshouldbecorrectlycasttoanint,而是当我们错误地将其转换为int时会发生什么。所以考虑一下这段代码-@TestpublicvoidlongTest(){longlongNumber=Long.MAX_VALUE;intintNumber=(int)longNumber;//potentiallyunsafecast.System.out.println("longNumber="+longNumber);System.out.println("intNumber="+intNumber);}这给出了输出-longNumber=92233

java - 在 Java 中,int cast 的工作时间有多长?

这个问题不是关于longshouldbecorrectlycasttoanint,而是当我们错误地将其转换为int时会发生什么。所以考虑一下这段代码-@TestpublicvoidlongTest(){longlongNumber=Long.MAX_VALUE;intintNumber=(int)longNumber;//potentiallyunsafecast.System.out.println("longNumber="+longNumber);System.out.println("intNumber="+intNumber);}这给出了输出-longNumber=92233

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