While reading some Java source, I came across this line:
((Closeable) some_obj).close();
some_obj is obviously an instance of a class that implements the Closeable interface. My question is: why do they first throw some_obj into Closeable before calling close (). I can not just do
some_obj.close();
Assuming the compile-time type some_objimplements Closeable, then yes, you could.
some_obj
Closeable
, , , , Closeable, - ( Object) "" (, ).
Object
, # , , - . , - , , .
some_obj close(), .
close()
, . ( , .)
, , , . , some_obj . , ...
() , , . , Java JIT . , , , .
Source: https://habr.com/ru/post/1755675/More articles:вставка значения с плавающей точкой с культурой, где запятая (,) используется для "с плавающей запятой", - c#Calculate time difference (hours of operation only) in minutes between two dates - sqlHow do you select versions from a specific branch in ClearCase? - clearcaseLINQ to SQL and SqlDependency - sqljavascript conflict - javascriptadd VML elements (images) using javascript - javascriptEclipse - default is JUnit 3 - eclipseNo JSF2.0 tags found - javaWindows SID - windows-identityHow to convert a Foreach loop to Linq (in a datagridview) - c #All Articles