Issue about casting object brackets

前端 未结 6 612
無奈伤痛
無奈伤痛 2020-12-21 01:13

I have noticed that there are two ways to cast objects (the difference is the placement of the outer parenthesis):

 1. SimpleType simpleType = ((SimpleType)          


        
6条回答
  •  一向
    一向 (楼主)
    2020-12-21 01:51

    They are doing two totally unrelated things: first is dowcasting the result of getType() and the second is downcasting the property variable. The first one looks like the one you need, given the type of the left-hand side. Note that in the first example you have extra parentheses, this would be enough, and is how this is idiomatically written:

    SimpleType simpleType = (SimpleType) property.getType();
    

提交回复
热议问题