情况1
byte b = 7; // why don't I need to cast 7 to byte in this case? byte b = (byte)7;
System.out.println(b);
Run Code Online (Sandbox Code Playgroud)
输出: 7
案例2
static void fun(byte b) {
System.out.println(b);
}
public static void main(String []args) {
fun(7); // Compiler gives error because a cast is missing here.
}
Run Code Online (Sandbox Code Playgroud)
输出:
编译错误:method fun(byte) is not applicable for the argument (int).
我的问题是:在案例1中,如何从一个7隐式地转换byte为int,而在案例2中它强制程序员明确地转换它?
7仍在范围内byte.
请建议.
我正在尝试使用 mongodb shell 登录 mongodb 数据库,如果密码包含任何特殊字符,例如 -(连字符) 或 '(单引号) ,则会出现错误 - Error parsing command line: unrecognised option '-8B'df5='。
mongo -u username -p -8B'df5= --authenticationDatabase admin
Run Code Online (Sandbox Code Playgroud)
请帮忙