Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why parameter.getType().isInstance(HttpServletRequest.class) return is false,but use "==" is true

Parameter[] ps = method.getParameters();

Map<String,Integer> map = new HashMap<String,Integer>();

for(int ij = 0;ij<ps.length;ij++){

    Parameter p = ps[ij];

    RequestParam rp = p.getAnnotation(RequestParam.class);

    if(rp != null){

        //do something

    }else {
        System.out.println(p.getType());
        System.out.println(p.getType().isInstance(HttpServletRequest.class));
        System.out.println(p.getType() == HttpServletRequest.class);
    }
}

the output is:

interface javax.servlet.http.HttpServletRequest
false
true

why use the "isInstance" is false and use "==" is true? because the "instance of" can't judge implements relationship?

like image 578
wkzq Avatar asked Jun 10 '16 10:06

wkzq


1 Answers

The type isn't an instance of the HttpServletRequest class, it's an instance of java.lang.Class that contains the information about the HttpServletRequest class.

like image 184
Mureinik Avatar answered Sep 20 '22 20:09

Mureinik