Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/defaulted/GetFieldWrite.java
38828 views
/*1* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 418073525*26* @clean GetFieldWrite Foo TestClass27* @build GetFieldWrite28* @run main GetFieldWrite29* @clean GetFieldRead TestClass30* @build GetFieldRead31* @run main GetFieldRead32*33* @summary Make sure that fields that are defaulted can be of primitive and34* object type.35*36*/3738import java.io.*;39class TestClass implements Serializable {4041private static final long serialVersionUID = 5748652654655279289L;4243// Fields to be serialized.44private final static ObjectStreamField[] serialPersistentFields = {45new ObjectStreamField("objectI", Integer.class)};4647Integer objectI;48int primitiveI;49Foo foo;5051public TestClass(Foo f, Integer I, int i) {52foo = f;53objectI = I;54primitiveI = i;55}56};5758public class GetFieldWrite {59public static void main(String[] args)60throws ClassNotFoundException, IOException61{62FileOutputStream fos = new FileOutputStream("data.ser");63ObjectOutput out = new ObjectOutputStream(fos);64out.writeObject(new TestClass(new Foo(100, 200), new Integer(100),65200));66out.close();67}68};6970/*71* Test class to be used as data field72*/73class Foo implements Serializable{74int a;75int b;76public Foo() {77a = 10; b= 20;78}7980public Foo(int a1, int b1)81{82a = a1; b = b1;83}8485public String toString() {86return new String("a = " + a + " b = " + b);87}88}899091