max
max

Reputation: 13

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();

Upvotes: 0

Views: 93

Answers (4)

Ozair Kafray
Ozair Kafray

Reputation: 13539

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

Upvotes: 2

patapizza
patapizza

Reputation: 2398

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.

Upvotes: 0

zawhtut
zawhtut

Reputation: 8561

It's depend on what getAllLevels method is returning.

Upvotes: 0

Jim
Jim

Reputation: 22656

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

Upvotes: 0

Related Questions