I'm trying to add a function that add a unique id to an object in java.
I've a function that returns me an object:
ItemStack is=ent.getKiller().getItemInHand();
I made a java class that extends ItemStack class and i tryied to cast the object to this class.
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public class UniqueItem extends ItemStack{
private String uid="";
public UniqueItem(){
uid=UUID.randomUUID().toString();
}
public String getUniqueID(){
return uid;
}
}
UniqueItem is=(UniqueItem)ent.getKiller().getItemInHand();
It produce me an error and i don't undersatand why.
Please help me to solve my problem or give me an alternative solution.
Thanks
ItemStackis not aUniqueItem, thus you cannot cast it that way around. ButUniqueItemis aItemStackand you can castUniqueItemtoItemStack