java:object_serialization

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
java:object_serialization [2017/02/17 14:03]
gthanos
java:object_serialization [2017/02/17 14:07]
gthanos
Line 48: Line 48:
    ​public String address;    ​public String address;
    ​public int AMKA;    ​public int AMKA;
-   ​public ​transient ​double salary; +   ​public double salary; 
-   ​public ​transient ​Employee next; +   ​public Employee next; 
-   ​public ​transient ​ArrayList<​Employee>​ list;+   ​public ArrayList<​Employee>​ list;
        
    ​public String toString() {    ​public String toString() {
Line 156: Line 156:
 </​code>​ </​code>​
  
 +<WRAP todo 80% center round>
 +Στο παραπάνω παράδειγμα δηλώστε τα τελευταία τρία πεδία της κλάσης Employee ως transient, oπως παρακάτω. Μεταγλωττίστε και τρέξτε ξανά τις κλάσεις **SerializeDemo** και **DeserializeDemo**. Τι παρατηρείτε;​
 +</​WRAP>​
 +
 +<code java Employee.java>​
 +import java.util.*;​
 +
 +public class Employee implements java.io.Serializable {
 +   ​public String name;
 +   ​public String address;
 +   ​public int AMKA;
 +   ​public transient double salary;
 +   ​public transient Employee next;
 +   ​public transient ArrayList<​Employee>​ list;
 +   
 +   ​public String toString() {
 +      String str = "Name: " + name+"​\n";​
 +      str+="​Address:​ " + address+"​\n";​
 +      str+="​AMKA:​ " + AMKA+"​\n";​
 +      str+="​Salary:​ " + salary+"​\n";​
 +      if(next != null)
 +        str+="​Next:​ " + next.name+"​\n";​
 +      ​
 +      if( list != null) {
 +        Iterator<​Employee>​ it = list.iterator();​
 +        if( it.hasNext() ) {
 +          str+="​List:​ ";
 +        }
 +        while( it.hasNext() ) {
 +          str+= it.next().name+",​ ";
 +        }
 +        str+="​\n";​
 +      }
 +      return str;
 +   }
 +}
 +</​code>​
  
  
 +|Προηγούμενο:​ [[ :​java:​write_to_file | Γράφοντας σε αρχείο ]] | [[ :toc | Περιεχόμενα ]] | Επόμενο:​ [[ :​java:​generics | Παραμετρικοί τύποι δεδομένων ]] |
  
  
java/object_serialization.txt · Last modified: 2017/02/17 14:11 by gthanos