Timeline for Alternative to Reflection
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 13, 2018 at 6:01 | history | tweeted | twitter.com/StackSoftEng/status/1040118221599383552 | ||
| Sep 5, 2018 at 13:10 | comment | added | Neil | @FaizanMubasher I think it's important to distinguish between using reflection to instantiate a class and using reflection unnecessarily. You should avoid reflection if you're using it to write "clever code". Don't write clever code, though reflection is still sometimes necessary under such circumstances. | |
| Sep 5, 2018 at 13:02 | comment | added | Faizan Mubasher | @Neil You got it right. I think I should stick with Reflection. This is the only possible solution for this scenario. | |
| Sep 5, 2018 at 11:00 | comment | added | Richard | First ask yourself what your problem is with reflection. Java is built on reflection.. it's a fundamental part of the language. It's just code like all your other code. If it is just that your security team doesn't like it.. get them to say why.. Other than that you'll need to maintain a mapping of classes to names. Perhaps using an Enum. See factory method answer below also. But don't change your code for no good reason. | |
| Sep 5, 2018 at 10:14 | answer | added | Ewan | timeline score: 2 | |
| Sep 5, 2018 at 9:30 | comment | added | Neil | Creating an instance of a class given its name is unavoidable if you aren't willing to hardcode it in your program. It is considered to be more flexible this way. Why do you need to remove it? The alternative being a gigantic enum or table which directly associates an id to its handler class. | |
| Sep 5, 2018 at 9:30 | review | Close votes | |||
| Sep 13, 2018 at 3:05 | |||||
| Sep 5, 2018 at 9:27 | comment | added | Quido | Could you elaborate on what actually the problem is with it? Why is it a problem? And how are you using Reflection exactly? I'm guessing that you would have a list of possible controllers somewhere (probably based on an interface) and then examine them to see it they can handle a specific machine id? | |
| Sep 5, 2018 at 9:10 | review | First posts | |||
| Sep 9, 2018 at 19:02 | |||||
| Sep 5, 2018 at 9:05 | history | edited | Kilian Foth | CC BY-SA 4.0 |
edited title
|
| Sep 5, 2018 at 9:03 | history | asked | Faizan Mubasher | CC BY-SA 4.0 |