小编Hri*_*tik的帖子

使用接口引用访问java Object类方法

让我们考虑以下示例.

public interface SimpleInterface {
    public void simpleMethod();
}

public class SimpleClass implements SimpleInterface{

 public static void main(String[] args) {
     SimpleInterface iRef = new SimpleClass();
     SimpleClass cRef = new SimpleClass();
     iRef.simpleMethod(); // Allowed. Calling methods defined in interface via interface reference.
     cRef.specificMethod(); // Allowed. Calling class specific method via class reference.
     iRef.specificMethod(); // Not allowed. Calling class specific method via interface reference.
     iRef.notify(); // Allowed????

 }

 public void specificMethod(){}

 @Override
 public void simpleMethod() {}

}
Run Code Online (Sandbox Code Playgroud)

我想,在使用接口引用的Java中,我们可能只访问在此接口中定义的方法.但是,似乎允许通过任何接口引用访问类Object的方法.我的具体类"SimpleClass"继承了Object类所具有的所有方法,并且类Object确实没有实现任何接口(假设Object使用notify,wait等方法实现某些接口).我的问题是,为什么允许通过接口引用访问类Object的方法,同时考虑到我的具体类中的其他方法是不允许的?

java inheritance interface

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

GCC 上 x86 intel asm 中方括号前的偏移量

从我发现的所有文档中,没有提到像offset[var+offset2]Intel x86 语法那样的语法,但是 GCC 有以下标志

gcc -S hello.c -o - -masm=intel

对于这个程序

#include<stdio.h>
int main(){
    char c = 'h';
    putchar(c);
    return 0;
}

Run Code Online (Sandbox Code Playgroud)

产生

    .file   "hello.c"
    .intel_syntax noprefix
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    push    rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    mov rbp, rsp
    .cfi_def_cfa_register 6
    sub rsp, 16
    mov BYTE PTR -1[rbp], 104
    movsx   eax, BYTE PTR -1[rbp]
    mov edi, eax
    call    putchar@PLT
    mov eax, 0
    leave
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size …
Run Code Online (Sandbox Code Playgroud)

x86 assembly gcc gnu-assembler intel-syntax

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