Issue about casting object brackets

前端 未结 6 624
無奈伤痛
無奈伤痛 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:40

    No they are not doing the same thing.

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

    First the property.getType() will be called and the object returned by property.getType() will be casted to SimpleType

    and in the second case

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

    first the object property will be casted to SimpleType and then getType() will be invoked on that newly casted object

提交回复
热议问题