开发者

Why is there a curled bracket on the List?

Recently stumped upon this line in a program, and I have no idea what the bracket for (List<Level>) is for . Anybody got any开发者_运维百科 idea ?

List<Level> levelList = (List<Level>)dao.getAllLevels();


Its called typecasting. The data returned from dao.getAllLevels() is being casted into type List.

This operation might not always be successful, and in that case jvm/jre throws a ClassCastException. You can read more about object typecasting in Java here.

More about java and type-casting on Stackoverflow:

  1. Java Type-casting Question


This casts the result of dao.getAllLevels(); to a List


It's depend on what getAllLevels method is returning.


It's called a cast. It's used to enforce the type of the following variable, in this case, to be sure that dao.getAllLevels() returns an object of type List.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜