java - 错误:不兼容的类型:布尔值无法转换为 int
问题描述
我收到错误:不兼容的类型:在 Android Studio 中编译 android 应用程序时,布尔值无法转换为 int错误。问题只有一种方法。
private static int get_wx_inx(String str) {
boolean equalsIgnoreCase = str.equalsIgnoreCase("木");
int equalsIgnoreCase2 = str.equalsIgnoreCase("火");
if (str.equalsIgnoreCase("土")) {
equalsIgnoreCase2 = true;
}
if (str.equalsIgnoreCase("金")) {
equalsIgnoreCase2 = 3;
}
return str.equalsIgnoreCase("水") ? 4 : equalsIgnoreCase2;
}
我不知道有什么问题。你能帮我找出问题所在吗?提前致谢。
解决方案
您可以在 switch 语句中使用字符串并返回相应的 int 值。
https://docs.oracle.com/javase/7/docs/technotes/guides/language/strings-switch.html
因为我们不能有混合类型的返回值。您可以考虑 0(FALSE) 和 1(TRUE)。或任何这样的随机值。
推荐阅读
- c++ - 如何在 C++ 中将两个相对 URI 合并为一个
- python - I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] 未启用任何 MLIR 优化通道(已注册 2)
- amazon-web-services - AWS Quicksight - 具有相同设置的多个图表
- css - 在网格中围绕一定数量的元素包裹标签
- azure-functions - 本地 Azure Functions 是否适合生产?
- storybook - 如何获取故事书以获取自定义事件
- asp.net - Azure 应用服务是否支持 ASP.NET 4.6.1 版本?
- flutter - 自定义日历,如 Google Flutter
- performance - 获取非常大的文本文件的长度统计信息
- javascript - Javascript - 一键下载多个链接