小编Jof*_*sey的帖子

在new关键字后省略通用参数

两条线之间有什么区别吗?

SomeClassOrInterface<Type1> name = new SomeClass<Type1>();
SomeClassOrInterface<Type1> name = new SomeClass<>();
Run Code Online (Sandbox Code Playgroud)

java generics

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

为什么ReadOnlyCollection <T>不是ReadOnlyCollection <out T>?

ReadOnlyCollection<T>仅支持阅读操作.为什么T没有标记out关键字?

c# generics

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

在编译时进行通用类型检查

让我们看一些Set<E>方法声明.

public boolean add(E e);
public E get(int index);
Run Code Online (Sandbox Code Playgroud)

让我们尝试使用它.

List<Boolean> list = new ArrayList<Boolean>();
Integer i = list.get(0);              //Predictably, here we get a compile error.
list.contains(new Integer(3));        //But this line is allowed. Why?
Run Code Online (Sandbox Code Playgroud)

即使在这个代码的非泛型等价物中(我知道,它只会转换成它),我们在两行中都会遇到编译错误.

List s = new ArrayList();
s.contains((Boolean)(new Integer(3)));
Integer i = (Boolean)s.get(3);
Run Code Online (Sandbox Code Playgroud)

那么为什么我不能在通用案例中得到错误?

java generics

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

atoi()是C标准的一部分吗?

atoi()C标准的一部分吗?

我应该用什么来转换char*intif atoi()不标准化?

c type-conversion atoi

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

为什么返回不复制对象?

以下代码仅打印A::A(),但不打印A::A(const A&)operator=.为什么?

struct A
{
  A()               { cout << "A::A()" << endl; }
  A(const A& value) { cout << "A::A(const A&)" << endl; }

  A& operator=(const A& newValut)
  {
    cout << "A::operator=" << endl; 
    return *this;
  }
};

A foo()
{
  A a;      //Ok, there we have to create local object by calling A::A().
  return a; //And there we need to copy it, otherwise it will be destroyed
            //because it's local object. But we …
Run Code Online (Sandbox Code Playgroud)

c++ return copy-constructor

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

双重条件而已

以下语句在Java中的含义是什么?

while(condition_1) {
    do something...
} while (condition_2);
Run Code Online (Sandbox Code Playgroud)

有没有真实的情况可以使用它?

更新:代码示例

    int i = 3;
    while (i < 10) {
        System.out.println(i++);
    } while (i < 15);
Run Code Online (Sandbox Code Playgroud)

java while-loop java-7

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

标签 统计

generics ×3

java ×3

atoi ×1

c ×1

c# ×1

c++ ×1

copy-constructor ×1

java-7 ×1

return ×1

type-conversion ×1

while-loop ×1