小编bla*_*234的帖子

C#和Java的三元运算符之间的区别(?:)

我是C#新手,我遇到了一个问题.处理三元运算符(? :)时,C#和Java之间存在差异.

在以下代码段中,为什么第4行不起作用?编译器显示错误消息there is no implicit conversion between 'int' and 'string'.第5行不起作用.两者List都是对象,不是吗?

int two = 2;
double six = 6.0;
Write(two > six ? two : six); //param: double
Write(two > six ? two : "6"); //param: not object
Write(two > six ? new List<int>() : new List<string>()); //param: not object
Run Code Online (Sandbox Code Playgroud)

但是,相同的代码适用于Java:

int two = 2;
double six = 6.0;
System.out.println(two > six ? two : six); //param: double
System.out.println(two > six ? two : …
Run Code Online (Sandbox Code Playgroud)

c# java ternary-operator conditional-operator

94
推荐指数
5
解决办法
4595
查看次数

使用三元运算符引发已检查或未检查的异常

用我原来的问题FileNotFoundException,并IllegalStateException因此它们被包含在了答案。我让他们改变了自己的超类IOException,并RuntimeException分别进行简单。


编译(不使用三进制,1个选中,1个未选中):

private void test() throws IOException { // throws is required
    if (new Random().nextInt(2)==0) throw new IOException();
    throw new RuntimeException();
}
Run Code Online (Sandbox Code Playgroud)

这也会编译(使用三元,2个未经检查的异常):

private void test3() { // throws not required
    throw new Random().nextInt(2)==0 ? new UncheckedIOException(null) : new RuntimeException();
}
Run Code Online (Sandbox Code Playgroud)

但是为什么不编译(使用三进制,1个选中的,1个未选中的)?

private void test2() throws IOException {
    throw new Random().nextInt(2)==0 ? new IOException() : new RuntimeException();
}
Run Code Online (Sandbox Code Playgroud)

从Eclipse:

未处理的异常类型Exception

2个快速修复可用:

J! 添加引发声明

J! 环绕尝试/捕捉


另一个例子

这样编译:

private void test4() { // …
Run Code Online (Sandbox Code Playgroud)

java exception ternary-operator

7
推荐指数
1
解决办法
217
查看次数

Spring Cloud 配置服务器 GitHub SHA-1 错误

语境

\n

这是关于 Spring Cloud Config Server业余爱好项目(带有@EnableConfigServer)。

\n

昨天,可以开始申请了。

\n

今天,由于 Git 通信错误,应用程序无法启动。

\n

GitHub 的官方博客文章中提到,从 2022 年 3 月 15 日开始,不再支持 SHA-1。这解释了我这两天得到的结果。

\n
\n

2022 年 3 月 15 日

\n

改变成为永久性的。

\n

我们\xe2\x80\x99将永久停止接受 DSA 密钥。在上述截止点之后上传的 RSA 密钥仅适用于 SHA-2 签名(但同样,在此日期之前上传的 RSA 密钥将继续适用于 SHA-1)。已弃用的 MAC、密码和未加密的 Git 协议将被永久禁用。

\n
\n

即使我没有删除现有的 SSH 密钥,今天仍然无法启动。但无论如何,现在存储库设置的“部署密钥”部分下的唯一密钥是 2022 年 3 月 15 日截止日期之后添加的 SSH 密钥。

\n
\n

依赖版本

\n

依赖管理:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n
依赖性版本
spring-cloud-依赖项霍克斯顿.SR12
\n
\n

依赖关系: …

spring github spring-cloud

6
推荐指数
1
解决办法
4998
查看次数