Structures
Basic structure
Java
public class Student {
public String name;
public int age;
public Student(String name, String age) {
this.name = name;
this.age = age;
}
}
GoLang
type Student struct {
Name string
Age int
}
Structure initialization
Java
var student = new Student("John", 18);
GoLang
student := Student{"John", 18}
Optional arguments in initialization
Java
public class Student {
private String name;
private int age;
public Student(String name) {
this.name = name;
}
public Student(String name, String age) {
this.name = name;
this.age = age;
}
}
var student = new Student("John");
GoLang
student := Student{"John"}