Java 条件运算符?:类型评估 void方法(设置whiteListProviders){ HashSet hashedWhitelistedProviders; HashSet fdsfh=(hashedWhitelistedProviders=(HashSet)whitelistedProviders); HashSet ghjk=(hashedWhitelistedProviders=新HashSet(whitelistedProviders)); HashSet gh4jk=true?fdsfh:ghjk;//编译 true?fdsfh:ghjk;//给出错误“类型不匹配:无法从哈希集转换为布尔值” }

Java 条件运算符?:类型评估 void方法(设置whiteListProviders){ HashSet hashedWhitelistedProviders; HashSet fdsfh=(hashedWhitelistedProviders=(HashSet)whitelistedProviders); HashSet ghjk=(hashedWhitelistedProviders=新HashSet(whitelistedProviders)); HashSet gh4jk=true?fdsfh:ghjk;//编译 true?fdsfh:ghjk;//给出错误“类型不匹配:无法从哈希集转换为布尔值” },java,conditional,Java,Conditional,我读 但是仍然无法理解为什么它在eclipse中给出编译错误Java只允许在需要语句的地方进行赋值和调用,而不允许任意表达式 从第节: 某些类型的表达式可用分号作为语句: void method(Set<String> whiteListProviders){ HashSet<String> hashedWhitelistedProviders; HashSet<String> fdsfh = (hashedWhitelis

我读
但是仍然无法理解为什么它在eclipse中给出编译错误Java只允许在需要语句的地方进行赋值和调用,而不允许任意表达式

从第节:

某些类型的表达式可用分号作为语句:

void method(Set<String> whiteListProviders){

        HashSet<String> hashedWhitelistedProviders;

        HashSet<String> fdsfh = (hashedWhitelistedProviders = (HashSet<String>) whitelistedProviders);

        HashSet<String> ghjk = (hashedWhitelistedProviders = new HashSet<String>(whitelistedProviders));

        HashSet<String> gh4jk = true ? fdsfh : ghjk; //compiles

        true?fdsfh:ghjk; //gives error "Type mismatch: cannot convert from HashSet<String> to boolean" 




}

三元运算符(
ConditionalExpression
)不在该列表中,因此它只能作为较大表达式或初始值设定项的一部分出现。

Java只允许在需要语句的地方进行赋值和调用,而不允许任意表达式

从第节:

某些类型的表达式可用分号作为语句:

void method(Set<String> whiteListProviders){

        HashSet<String> hashedWhitelistedProviders;

        HashSet<String> fdsfh = (hashedWhitelistedProviders = (HashSet<String>) whitelistedProviders);

        HashSet<String> ghjk = (hashedWhitelistedProviders = new HashSet<String>(whitelistedProviders));

        HashSet<String> gh4jk = true ? fdsfh : ghjk; //compiles

        true?fdsfh:ghjk; //gives error "Type mismatch: cannot convert from HashSet<String> to boolean" 




}

三元运算符(
ConditionalExpression
)不在该列表中,因此它只能作为更大表达式或初始值设定项的一部分出现。

我认为这甚至不是一个独立的有效语句。神圣的变量名,蝙蝠侠!对梅来说,这是一个棘手但有趣的问题。别认为这是一个独立的有效语句。神圣的变量名,蝙蝠侠!对我来说,这是一个棘手但有趣的问题