草庐IT

Implicit_cast

全部标签

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

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 - 为什么混合 + 和 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参数的函数调用。