INRIA / INRIA/spoon

How to put constructors and methods in the same list?

Open
#2,719 7 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

I want to save methods and constructors of any class under one list.
This is sample of what Im doing
private static List> GetMethodsnConstructor(CtModel model){
List> Allconstructornmethods = new ArrayList>();
List> constructors= model.getElements(new TypeFilter>(CtConstructor.class));
Allconstructornmethods = model.getElements(new TypeFilter>(CtMethod.class));
for(CtConstructor constructor: constructors)
{
if(!(constructor.isImplicit())) {

Allconstructornmethods.add((CtMethod)constructor);
}
}
return Allconstructornmethods;
}

Im saving it to Allconstructornmethods which is CtMethod Type list and getting an error at
Allconstructornmethods.add((CtMethod)constructor);
as error says I canot caste constructor to methods . is there any other way ?
thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.