小编Yat*_*ney的帖子

如何在java中的静态上下文中定义成员接口?

成员接口只能在顶级类或接口内或静态上下文中定义.

案例A:顶级类中的接口完美运行

package multiplei.interfaces.test;

public class InterfaceBetweenClass {

    interface Foo {
        void show();
    }

    class InnerClass implements Foo{
        public void show(){
            System.out.println("Inner Class implements Foo");
        }
    }

    public static void main(String[] args) {
        new InterfaceBetweenClass().new InnerClass().show();
    }

}
Run Code Online (Sandbox Code Playgroud)

案例B:界面内的界面运行良好.

public interface Creatable {
    interface Foo{
        void show();
    }}
Run Code Online (Sandbox Code Playgroud)

案例C:我知道为什么有人会在静态上下文中定义接口听起来很愚蠢.但是当我尝试在静态上下文中定义接口时,它会给我相同的错误消息.

package multiplei.interfaces.test;

public class InterfaceBetweenClass {
    public static void main(String[] args) {
        interface Foo {  //Line 5
            void show(); 
        }
    }

}}
Run Code Online (Sandbox Code Playgroud)

但第5行给出了以下错误消息"The member interface Foo can …

java static interface

9
推荐指数
1
解决办法
568
查看次数

在Android Studio中启动模拟器时出错

启动Android虚拟设备管理器时出现以下错误:

> C:\Users\yates\AppData\Local\Android\sdk\tools\emulator.exe -netdelay
> none -netspeed full -avd Nexus_5_API_23_x86 <br/> init: Could not find
> wglGetExtensionsStringARB! <br/> emulator: WARNING: Classic qemu does
> not support SMP. The hw.cpu.ncore option from your config file is
> ignored.<br/> getGLES1ExtensionString: Could not find GLES 1.x
> config!<br/> emulator: device fd:704<br/> Failed to obtain GLES 1.x
> extensions string!<br/> HAXM is working and emulator runs in fast virt
> mode<br/> Could not initialize emulated framebufferCannot set up guest
> memory …
Run Code Online (Sandbox Code Playgroud)

android android-studio

5
推荐指数
1
解决办法
4943
查看次数

为什么内部类实例会在内存中进行remian,即使外部类对象被销毁了?

请考虑以下两个类:

一个学生

package datatypes;

public class Student {

    private String name ;

    public Student(String name) {
        this.name = name;
    }

    class Address{
        String city;
        String state;

        Address(String city , String state){
            this.city = city;
            this.state = state;
        }

        String getAddress(){
            return city + state;
        }

    }

    String getName(){
        return name;
    }
}
Run Code Online (Sandbox Code Playgroud)

b.)StudentDemo

package datatypes;

import datatypes.Student.Address;

public class StudentDemo {
    public static void main(String[] args) {
        Student obj = new Student("Yati");
        Address adr = obj.new Address("YNR" , "HARYANA");

        System.out.println(obj.getName()); …
Run Code Online (Sandbox Code Playgroud)

java garbage-collection inner-classes local-class

1
推荐指数
1
解决办法
456
查看次数

Hashcode和Equals实现

考虑以下HashMap实现

HashMap<String,String> hashMap=new HashMap<>();
hashMap.put(new String("ABC"), "Hello");
hashMap.put("ABC", "Hello");
System.out.println(hashMap.size());
Run Code Online (Sandbox Code Playgroud)

如何size评估代码内部的代码如何返回1?但是,如果我使用StringBuffer而不是String代码返回值为2.这背后的原因是什么?

java hash hashmap

-2
推荐指数
1
解决办法
129
查看次数