开发者

Why is there a curled bracket on the List?

开发者 https://www.devze.com 2023-03-09 19:09 出处:网络
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 ?

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

精彩评论

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