我有一个类定义如下:
public class Person {
private String name;
// constructor and getter/setter omitted
}
Run Code Online (Sandbox Code Playgroud)
我试图打印我的班级实例:
System.out.println(myPerson);
Run Code Online (Sandbox Code Playgroud)
但我得到了以下输出:com.foo.Person@2f92e0f4.
当我尝试打印一个Person对象数组时发生了类似的事情:
Person[] people = //...
System.out.println(people);
Run Code Online (Sandbox Code Playgroud)
我得到了输出: [Lcom.foo.Person;@28a418fc
这个输出是什么意思?如何更改此输出以使其包含我的人名?我如何打印我的对象集合?
注意:这是关于此主题的规范问答.
我真的很困惑为什么编码值不同
这是完整的代码
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.security.Key;
import java.security.KeyStore;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import org.bouncycastle.util.encoders.Base64;
public class KeyStoreDemo {
private static final String KEY_STORE_TYPE = "JCEKS";
private static final String KEY_STORE_NAME = "sampleKeyStore.store";
private static final String KEY_STORE_PASSWORD = "letmein";
public static void main(String[] args) throws Exception {
File storeFile = new File(KEY_STORE_NAME);
storeFile.createNewFile();
//Create a keystore
createKeyStore(KEY_STORE_TYPE, storeFile,KEY_STORE_PASSWORD);
//Generate a key and store it in keystore
KeyStore keyStore = loadKeyStore(KEY_STORE_TYPE,storeFile,KEY_STORE_PASSWORD);
// Get the KeyGenerator …Run Code Online (Sandbox Code Playgroud)