小编Dav*_*can的帖子

Java中传递接口引用和类引用之间的区别

如示例所示,传递接口引用或类引用之间有什么区别;

Interface MyInterface
{
     void foo();
}
public class MyClass implements MyInterface
{


 public void foo()
    {
        doJob();
    }
}

....
//in another class or etc..
public void case1(MyClass mc)
{
    mc.foo();
}

public void case2(MyInterface mi)
{
    mi.foo();
}
....
//In somewhere
MyClass mc = new MyClass();
case1(mc);
case2(mc);
Run Code Online (Sandbox Code Playgroud)

case1和case2之间的主要区别是什么?它们在性能,可见性,保护对象免受非法使用方面是否具有任何优势?像这样使用它有什么缺点吗?

java performance encapsulation interface object

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

为什么在cstring.h中没有在strcmp中使用常量指针

在cstring.h文件中存在一个函数:

int strcmp ( const char *s1, const char *s2 ),但为什么只有数据是常量,使指针和数据都不变更安全.在我看来,正确的函数版本应该是这样的:

int strcmp ( const char * const s1, const char * const s2 )
Run Code Online (Sandbox Code Playgroud)

c++ string const

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

标签 统计

c++ ×1

const ×1

encapsulation ×1

interface ×1

java ×1

object ×1

performance ×1

string ×1