任何人都可以告诉我为什么这句话工作正常:System.out.println(p [i]);

-2 java

阅读密码学,无法理解为什么指示的代码行打印数据:

Provider p[] = Security.getProviders()
for (int i = 0; i < p.length; i++) {
    System.out.println(p[i]); // <<<--- THIS LINE
Run Code Online (Sandbox Code Playgroud)

为什么打印数据如果它不是字符串,它是一个提供者对象

谢谢.

YCF*_*F_L 5

因为println()接受很多类型,例如这个方法有很多签名:

println(int i){...}               //when you set int you call this
println(String i){...}            //when you set String you call this
println(boolean i){...}           //when you set boolean you call this
println(char i){...}              //when you set char you call this
println(java.lang.Object i){...}  //when you set Object you call this
... and so on
Run Code Online (Sandbox Code Playgroud)

看一下java.lang.System

  • 没错,println接受一个对象作为参数.非常感谢,你很善良. (2认同)