import
java.lang.reflect.Method;
import
java.lang.reflect.Type;
public
class
GFG {
public
static
void
main(String[] args)
{
try
{
Class classobj = sample.
class
;
Method[] methods = classobj.getMethods();
for
(Method method : methods) {
if
(method.getName().equals(
"setValue"
)) {
int
count = containsParameter(
method,
(Type)java.lang.String.
class
);
System.out.println(
"No of String"
+
" Parameters in setValue(): "
+ count);
}
}
for
(Method method : methods) {
if
(method.getName().equals(
"setManyValues"
)) {
int
count = containsParameter(method,
(Type)
int
.
class
);
System.out.println(
"No of int Parameters"
+
" in setManyValues(): "
+ count);
}
}
}
catch
(Exception e) {
e.printStackTrace();
}
}
private
static
int
containsParameter(Method method,
Type parameterName)
{
int
count =
0
;
Type parameters[] = method.getGenericParameterTypes();
for
(
int
i =
0
; i < parameters.length; i++) {
if
(parameters[i] == parameterName) {
count++;
}
}
return
count;
}
}
class
sample {
public
void
setValue(String value1,
String value2)
{
System.out.println(
"setValue"
);
}
public
void
setManyValues(
int
value1,
double
value2,
String value3)
{
System.out.println(
"setManyValues"
);
}
}