Skip to content

How to put constructors and methods in the same list? #2719

Open
@mashalahmad

Description

@mashalahmad

I want to save methods and constructors of any class under one list.
This is sample of what Im doing
private static List<CtMethod> GetMethodsnConstructor(CtModel model){ List> Allconstructornmethods = new ArrayList<CtMethod>(); List> constructors= model.getElements(new TypeFilter<CtConstructor>(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions