![java reflection to avoid if statements java reflection to avoid if statements](https://i.stack.imgur.com/BOTy6.jpg)
Java reflection to avoid if statements code#
If statements are for controlling the flow of code and can be used within property get/set accessor, or functions.Ĭlick to expand.I'm just trying to understand what Kurt is trying to explain to me above^. So, anything you can do with c#'s Get and Set accessors can be done with functions, but they're a neat language feature for simplifying code and thinking in an OO mindset.
![java reflection to avoid if statements java reflection to avoid if statements](http://www.testingdocs.com/wp-content/uploads/Area-of-Circle-C-Program.png)
They're a bit simpler in this regard, but this is because of their intended use - to define a class' properties.
![java reflection to avoid if statements java reflection to avoid if statements](https://technicaljungle.com/wp-content/uploads/2019/03/image-11-1720x459.png)
If you're thinking in an Object-Orientated way, you should think of a class' "properties" and get/set allow you to control how they're accessed and written to.Īnother is that you can pass parameters into a function, whereas you can't to the get or set accessors. One is simply cosmetic - they allow you to define a "property" of a particular class and keep a class' properties seperate from the logic of the class, which should be contained in functions. You may, however, want to use a Get accessor instead, for a few reasons. ^That's a legitimate way to find the half height value within this class.