内部类不能有静态声明 - public static final String []

时间:2018-05-21 01:55:24

标签: java android arrays string

我在第5行遇到了问题

public static final String[] CREATIVE_SDK_SCOPES = { "email", "profile", "address" };

  

内部类不能有静态声明

 public final class Keys {
    public static final String CREATIVE_SDK_CLIENT_ID = "xxxxxxxx";
    public static final String CREATIVE_SDK_CLIENT_SECRET = "xxxxxxxxx";
    public static final String CREATIVE_SDK_REDIRECT_URI = "xxxxxxxxxx";
    public static final String[] CREATIVE_SDK_SCOPES = { "email", "profile", "address" };
  }
  private static final String CREATIVE_SDK_CLIENT_ID = Keys.CREATIVE_SDK_CLIENT_ID;
  private static final String CREATIVE_SDK_CLIENT_SECRET = Keys.CREATIVE_SDK_CLIENT_SECRET;
  private static final String CREATIVE_SDK_REDIRECT_URI = Keys.CREATIVE_SDK_REDIRECT_URI;
  private static final String[] CREATIVE_SDK_SCOPES = Keys.CREATIVE_SDK_SCOPES;

inner classes cannot have static declarations

你能解释它的含义以及解决方法吗?

1 个答案:

答案 0 :(得分:2)

  

因为内部类与实例相关联,所以它本身不能定义任何静态成员。

https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html

您必须使用静态嵌套类。

public static final class Keys {