Advertisement
Alexallunited

Java vs Kotlin primer

Aug 29th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. /*  Java program */
  2.  
  3. public class Address {
  4.  
  5.  private String street;
  6.  
  7.  private int streetNumber;
  8.  
  9.  private String postCode;
  10.  
  11.  private String city;
  12.  
  13.  private Country country;
  14.  
  15.  public Address(String street, int streetNumber, String postCode, String city, Country country) {
  16.  
  17.   this.street = street;
  18.  
  19.   this.streetNumber = streetNumber;
  20.  
  21.   this.postCode = postCode;
  22.  
  23.   this.city = city;
  24.  
  25.   this.country = country;
  26.  
  27.  }
  28.  
  29.  @Override
  30.  public boolean equals(Object o) {
  31.   if (this == o) return true;
  32.  
  33.   if (o == null || getClass() != o.getClass()) return false;
  34.  
  35.   Address address = (Address) o;
  36.  
  37.   if (streetNumber != address.streetNumber) return false;
  38.  
  39.   if (!street.equals(address.street)) return false;
  40.  
  41.   if (!postCode.equals(address.postCode)) return false;
  42.  
  43.   if (!city.equals(address.city)) return false;
  44.  
  45.   return country == address.country;
  46.  }
  47.  
  48.  @Override
  49.  public int hashCode() {
  50.   int result = street.hashCode();
  51.  
  52.   result = 31 * result + streetNumber;
  53.  
  54.   result = 31 * result + postCode.hashCode();
  55.  
  56.   result = 31 * result + city.hashCode();
  57.  
  58.   result = 31 * result + (country != null ? country.hashCode() : 0);
  59.  
  60.   return result;
  61.  
  62.  }
  63.  
  64.  @Override
  65.  
  66.  public String toString() {
  67.  
  68.   return "Address{" +
  69.  
  70.    "street='" + street + '\'' +
  71.  
  72.    ",     streetNumber=" + streetNumber +
  73.  
  74.    ",     postCode='" + postCode + '\'' +
  75.  
  76.    ",     city='" + city + '\'' +
  77.  
  78.    ",     country=" + country +
  79.  
  80.    '}';
  81.  
  82.  }
  83.  
  84.  public String getStreet() {
  85.  
  86.   return street;
  87.  
  88.  }
  89.  
  90.  public void setStreet(String street) {
  91.  
  92.   this.street = street;
  93.  
  94.  }
  95.  
  96.  public int getStreetNumber() {
  97.  
  98.   return streetNumber;
  99.  
  100.  }
  101.  
  102.  public void setStreetNumber(int streetNumber) {
  103.  
  104.   this.streetNumber = streetNumber;
  105.  
  106.  }
  107.  
  108.  public String getPostCode() {
  109.  
  110.   return postCode;
  111.  
  112.  }
  113.  
  114.  public void setPostCode(String postCode) {
  115.  
  116.   this.postCode = postCode;
  117.  
  118.  }
  119.  
  120.  public String getCity() {
  121.  
  122.   return city;
  123.  
  124.  }
  125.  
  126.  public void setCity(String city) {
  127.  
  128.   this.city = city;
  129.  
  130.  }
  131.  
  132.  public Country getCountry() {
  133.  
  134.   return country;
  135.  
  136.  }
  137.  
  138.  public void setCountry(Country country) {
  139.  
  140.   this.country = country;
  141.  
  142.  }
  143.  
  144. }
  145.  
  146.  
  147.  
  148. /*  Kotlin Program */
  149.  
  150. data class Address(var street: String,
  151.  
  152.  var streetNumber: Int,
  153.  
  154.   var postCode: String,
  155.  
  156.    var city: String,
  157.  
  158.     var country: Country)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement