Private nested static class - Good or bad practice?

后端 未结 6 598
[愿得一人]
[愿得一人] 2021-01-04 03:20

Would it be considered a bad practice to nest a private static class inside of a non-static class?

public class Outer
{
    private static class Inner
    {
         


        
6条回答
  •  清歌不尽
    2021-01-04 04:06

    There's nothing wrong at all with this, and why should there be?

    The scope is limited, so that only instances of the outer class have access to it, and it's a great place to put constants and other common functionality that is private to the functionality of the outer class, without having to instantiate it all the time.

    I don't see this as anything but good practice.

提交回复
热议问题