Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Razvan Cirstea](https://secure.gravatar.com/avatar/1edf11b77484d0df2dd4bdded03c3190?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Razvan Cirstea
2,493 PointsUpcasting to (GridPane) questions
I don't understand the whole "GridPane example= (GridPane) root;" bit . I have so many questions about this :)
- Why do we need to go through all this "trouble" ? What is the purpose ?
- Why do we then decide we do not need to do so, and we erase that code ?
- Why do we upcast to (GridPane) , when we saw in the documentation it is the lowest library of all ?
I am sure I am missing something here ! Hope I'm not missing something ridiculously obvious :)
1 Answer
![Doli Harahap](https://uploads.teamtreehouse.com/production/profile-photos/5600272/micro_download.jpg)
Doli Harahap
6,246 PointsHi,
- Why do we need to go through all this "trouble" ? What is the purpose ?
- Why do we then decide we do not need to do so, and we erase that code ? Look at this FXMLLoader.load() https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/FXMLLoader.html#load--
It returns a generic type which is designed so programmer can return any type that defined in the FXML document. You don't have to do that, you can directly catch the Class:
GridPane root = FXMLLoader.load(getClass().getResource("sample.fxml"));
- Why do we upcast to (GridPane) , when we saw in the documentation it is the lowest library of all ? It's not like have to be GridPane, it follows your root tag in your FXML.
Hope it helps.