How do I define a single constructor public packet(String[] biscuit) which makes my field from private String[] biscuitList to private String[] biscuit?
How do I define a single constructor public packet(String[] biscuit) which makes my field
Share
Just assign it to the field.
The
thisrefers to the currentPacketinstance (which you just created usingnew Packet). Thethis.biscuitListrefers to thebiscuitListfield of the currentPacketinstance. The= biscuitassigns the givenbiscuitto the left hand (which in this case is thebiscuitListfield.That said, a
String[]variable shouldn’t really be called with a name ending inList. This may cause ambiguity with aList<String>. You can just call itbiscuit, or maybe better,biscuits.Also, classnames and constructor names ought to start with uppercase. I.e.
Packetand notpacket.To learn more about Java, check the Trials Covering the Basics.