Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Utilize generics while keeping typecasting minimum #247

Open
RESDXChgfore9hing opened this issue Jul 17, 2022 · 4 comments
Open

How to Utilize generics while keeping typecasting minimum #247

RESDXChgfore9hing opened this issue Jul 17, 2022 · 4 comments

Comments

@RESDXChgfore9hing
Copy link

currently if you have a java class and if you want to parse it(or obtain it) recursively.we need to do.

for(org.jboss.forge.roaster.model.JavaType jtypes:javaClass.getNestedTypes()){
			org.jboss.forge.roaster.model.source.JavaClassSource assumetypeiscls=(org.jboss.forge.roaster.model.source.JavaClassSource)jtypes;
.........

is there any way to just not cast it into a classsource?or maybe cast to a more genric type? that may include interface.

@gastaldi
Copy link
Member

JavaType is the generic type. You can invoke the isClass(),isInferface(), etc methods to figure out the type (or instanceof if you like)

@RESDXChgfore9hing
Copy link
Author

so i would need write ifelse checking and then cast the types accordingly?

Is there any more efficient way?

@gastaldi
Copy link
Member

In the meantime, yes. A Visitor pattern could be introduced in the API, with visit(...) methods for the existing types.

Would you like to contribute with it?

@RESDXChgfore9hing
Copy link
Author

hmm sadly I have never implemented a visitor API before,so I dont think i can contribute it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants