JustShinigami
Mitglied
Hallo liebe Community.
Zurzeit arbeite ich mit einem Freund an einem auf Java basierten Spiel. Da ich hauptsächlich in C# programmiere, will ich mir eine Eigenschaftenklasse machen, mit der ich ähnlich wie bei C# Eigenschaften nutzen kann.
Ich habe dafür 2 Klassen:
und
Jetzt sagt er mir die ganze Zeit:
Ich bin nicht so erfahren in Java, allerdings sollte die Methode "Set(PropertyType)" doch eigentlich die Methode "Set(Object)" nur überladen, oder nicht?
Mfg
JustShinigami
Zurzeit arbeite ich mit einem Freund an einem auf Java basierten Spiel. Da ich hauptsächlich in C# programmiere, will ich mir eine Eigenschaftenklasse machen, mit der ich ähnlich wie bei C# Eigenschaften nutzen kann.
Ich habe dafür 2 Klassen:
Java:
package SG;
/**
* Eigenschaftsklasse zum vereinfachen von Eigenschaften einer Klasse.
* @author Shinigami Games
*/
public class Property
{
private boolean _readonly;
private boolean _writeonly;
protected Object _field;
public Property()
{
this._readonly = false;
this._writeonly = false;
this._field = null;
}
public Property(Object DefaultValue)
{
this();
this._field = DefaultValue;
}
public Property(Object DefaultValue, int AccessMode)
{
this(DefaultValue);
switch (AccessMode)
{
case 1:
this._readonly = true;
case 2:
this._writeonly = true;
}
}
public static final int ReadOnly = 1;
public static final int WriteOnly = 2;
public Object Get()
{
if (this._readonly)
return this._field;
else return null;
}
public void Set(Object Value)
{
if (this._writeonly)
this._field = Value;
}
}
und
Java:
package SG.Generic;
/**
* Eigenschaftsklasse zum vereinfachen von Eigenschaften einer Klasse.
* @author Shinigami Games
*/
public class Property<PropertyType> extends SG.Property
{
public Property()
{
super();
}
public Property(PropertyType DefaultValue)
{
super(DefaultValue);
}
public Property(PropertyType DefaultValue, int AccessMode)
{
super(DefaultValue, AccessMode);
}
@Override
public PropertyType Get()
{
return (PropertyType)super.Get();
}
@Override
public void Set(Object Value) throws ClassCastException
{
try
{
PropertyType TempValue = (PropertyType)Value;
super.Set(Value);
}
catch (ClassCastException CastException)
{
throw new ClassCastException(CastException.getMessage());
}
}
public void Set(PropertyType Value)
{
super.Set(Value);
}
}
Jetzt sagt er mir die ganze Zeit:
Code:
error: name clash: Set(PropertyType) in SG.Generic.Property and Set(Object) in SG.Property have the same erasure, yet neither overrides the other
public void Set(PropertyType Value)
where PropertyType is a type-variable:
PropertyType extends Object declared in class SG.Generic.Property
Ich bin nicht so erfahren in Java, allerdings sollte die Methode "Set(PropertyType)" doch eigentlich die Methode "Set(Object)" nur überladen, oder nicht?
Mfg
JustShinigami
Zuletzt bearbeitet: