Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

ItemDetail has only private members and no getters #34

Closed
DaPutzy opened this issue Dec 8, 2017 · 3 comments
Closed

ItemDetail has only private members and no getters #34

DaPutzy opened this issue Dec 8, 2017 · 3 comments
Labels

Comments

@DaPutzy
Copy link

DaPutzy commented Dec 8, 2017

The class me.xhsun.guildwars2wrapper.model.v2.util.itemDetail.ItemDetail has only private members and no getters, or am i missing sth?

screen1

@xhsun
Copy link
Owner

xhsun commented Dec 8, 2017

Ah yes... that class is meant to be like that. If you go to the wiki page for items, you'll see depend on the type of that item, it will have different details.

So what I did at that time was to create a general item detail class that contains all kind of details I might need. Depend on the item type, each specific item detail class will grant you access to correct details. Those classes can be find in me.xhsun.guildwars2wrapper.model.v2.util.itemDetail package.

Thus, what I suggest you may want to do is get the item type use getType(), then cast what you get from getDetails() to the specific item detail class.

I'll probably add more javadoc for getDetails(), so that it is less confusing. But if you have any better suggestion, please let me know!

@xhsun xhsun added the question label Dec 8, 2017
@DaPutzy
Copy link
Author

DaPutzy commented Dec 10, 2017

I assume you meant it like that:

if (item.getType() == Item.Type.Weapon) {
    final Weapon weapon = (Weapon) item.getDetails();

    System.out.println(weapon);
}

that however throws this:

Exception in thread "main" java.lang.ClassCastException: me.xhsun.guildwars2wrapper.model.v2.util.itemDetail.ItemDetail cannot be cast to me.xhsun.guildwars2wrapper.model.v2.util.itemDetail.Weapon
at Main.main(Main.java:18)

This was referenced Dec 11, 2017
@xhsun
Copy link
Owner

xhsun commented Dec 11, 2017

Yep, that is what I meant.

I fixed the issue that caused ClassCastException, which means you can now downcast it without issue (hopefully).

@xhsun xhsun closed this as completed Dec 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants