I have this code:
package zargclient;
public class Skin {
protected String ID = "http://i.imgur.com/";
protected String Name = "";
protected boolean Locked = false;
protected boolean StaffName = false;
public static void main(String ID, String N, boolean L, boolean SN) {
Skin Result = new Skin();
Result.ID = ID;
Result.Name = N;
Result.Locked = L;
Result.StaffName = SN;
}
}
The problem here is that I want to add return Result;
to that code, but I can't since Java won't allow it. I can't use specific data arrays such as int[] Items = {1, 2, 3};
since I need to have the array contain strings and booleans.
Is there a solution around this, and if so, can any of you please explain it? I'm new to Java, so it'd be greatly appreciated <3
If you're wondering why I am using this: It's for a project I'm working on, where all 'skins' derive from this Skin class.
Since the method signature of main
is void
, you should create a new method which returns an Object of type Skin
.
package com.steve.research;
public class Skin {
protected String ID = "http://i.imgur.com/";
protected String Name = "";
protected boolean Locked = false;
protected boolean StaffName = false;
public static Skin createSkin(String ID, String N, boolean L, boolean SN) {
Skin result = new Skin();
result.ID = ID;
result.Name = N;
result.Locked = L;
result.StaffName = SN;
return result;
}
}
Or alternatively you could split the code into two classes, Skin
and SkinFactory
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.