+ 2
What is the use of a local class in java
is it really useful at all?
8 Réponses
+ 3
ifl hi,
A local inner class will have access to all the members of the enclosing class and it’ll have access to the local final variables in the scope it’s defined.
I think use of local class somehow on specific situation is required where we have to hide our data from outside of class like I have some examples from which I will try to explain you
1) first I take an example encoder decoder project => in this project I have to hide the encryption at encoder side and decryption at decoder side if I create two local classes which store and secure that data for me
2) in microprocessor all codes have some op codes so if I have to make microprocessor then I just create an local class and do everything op codes store in that class which is not accessible outside the class
3)https://coderanch.com/mobile/t/528900/java/Practical-real-world-situations-classes
https://www.dineshonjava.com/local-inner-classes-example-in-java/
I hope this link can help you I'm not good in explaining
+ 10
Mohit the coder (M.S.D)
Haha, I feel honored.
Let me just refer to the official tutorial, because it covers the topic perfectly.
The official tutorial is sometimes a little confusing and often long to read, but this chapter is really good.
Just ask if you have any further questions on the matter.
https://docs.oracle.com/javase/tutorial/java/javaOO/whentouse.html
+ 9
ifl may be this link can help you about local class use
https://www.quora.com/What-is-a-local-class-Why-is-it-used-in-code-What-are-the-benefits-Can-you-give-an-example
+ 5
GAWEN STEASY yes, thanks for the post. I saw it (or similar ) in quora, but I never felt I the need to use this myself, so checking what people think, or how it is used in real examples...
:-)
+ 5
well thanks but yeah if someone good in Java like Tashi N if she do share some knowledge on this then It would be good just in case she is free tagging you for the thread
+ 4
Mohit the coder (M.S.D) Interesting examples, thanks.
+ 3
Thanks Tashi N !
+ 2
For example: I used it in a blockchain application, in the blockchain class I made a seperate inner class mining. This makes the code more clean and readable.
Can be very usefull for testing/benchmarking as well.