小编Jan*_*sch的帖子

Java继承:将列表限制为子类对象

我们假设我有3个类:汽车,敞篷车和车库.

汽车:

public class Car {    
    private String name;
    private String color;

    public Car(String name, String color) {
        this.name = name;
        this.color = color;
    }    
    //Getters
}
Run Code Online (Sandbox Code Playgroud)

敞篷继承自汽车:

public class Convertible extends Car{
    private boolean roof;

    public Convertible(String name, String color, boolean roof) {
        super(name, color);
        this.roof = roof;
    }

    public boolean isRoof() {
        return roof;
    }
}
Run Code Online (Sandbox Code Playgroud)

车库存储汽车列表:

public class Garage {
    private int capacity;
    private List<Car> cars = new LinkedList<Car>();

    //Setter for capacity
}
Run Code Online (Sandbox Code Playgroud)

我怎么能创建一个只能存储Convertibles 的Garage被调用的子类 …

java generics collections inheritance list

12
推荐指数
2
解决办法
731
查看次数

Java Generics Call Constructor

假设我有四类:Car,Convertible,PickupTruckCarManufacturer.

Car是抽象类ConvertiblePickupTruck继承:

public abstract class Car {
    private String name;
    private String colour;

    //Constructor
}
Run Code Online (Sandbox Code Playgroud)

Convertible并且PickupTruck都有无参数构造函数:

public class Convertible extends Car {
    private boolean roofUnfolded;

    public Convertible() {
        super("Convertible", "Red");
        this.roofUnfolded = false;
    }
}

public class PickupTruck extends Car {
    private double capacity;

    public PickupTruck() {
        super("Pickup Truck", "Black");
        this.capacity = 100;
    }
}
Run Code Online (Sandbox Code Playgroud)

CarManufacturer存储一个Convertibles或的列表PickupTrucks.

public class CarManufacturer …
Run Code Online (Sandbox Code Playgroud)

java generics constructor list

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

win32gui MoveWindow() 未与屏幕左边缘对齐

我使用win32gui将记事本窗口移动到屏幕的原点 (0, 0),宽度和高度等于 500。结果是窗口没有移动到真正的左边框,而是 ~10 px。向右。宽度和高度也不等于 500 像素。(~620 像素。相反)。
我正在使用以下代码来生成我的结果。

import win32gui
from PIL import ImageGrab

# Open notepad.exe manually.
hwnd = win32gui.FindWindow(None, "Untitled - Notepad")
win32gui.MoveWindow(hwnd, 0, 0, 500, 500, True)
bbox = win32gui.GetWindowRect(hwnd)
img = ImageGrab.grab(bbox)
Run Code Online (Sandbox Code Playgroud)

这里是窗口在屏幕上的整体位置的截图:
在此处输入图片说明

这里有一张图片img在此处输入图片说明

python pywin32 win32gui python-imaging-library

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

[,]和$之间的逻辑陈述的差异

我正在处理一个数据框('df_temp'),其中有两列客户ID('Custid')和收入('收入'):

  Custid    Income
  <fctr>     <dbl>
1   1003  29761.20
2   1004  98249.55
3   1006  23505.30
4   1007  72959.25
5   1009 114973.95
6   1010  25038.30
Run Code Online (Sandbox Code Playgroud)

在检查收入是否为数字时,我遇到以下问题:

使用$来引用收入,返回TRUE:

> is.numeric(df_temp$Income)
[1] TRUE
Run Code Online (Sandbox Code Playgroud)

使用[,2]或[,(...())来引用收入,返回FALSE:

> i <- which(names(df_temp)=='Income')
> is.numeric(df_temp[,i])
[1] FALSE
> is.numeric(df_temp[,2])
[1] FALSE
Run Code Online (Sandbox Code Playgroud)

当尝试使用[,]将此向量设置为数字时,我遇到了另一个问题:

> df_temp[,2] <- as.numeric(df_temp[,2])
Run Code Online (Sandbox Code Playgroud)
Error: (list) object cannot be coerced to type 'double'
Run Code Online (Sandbox Code Playgroud)

我一直认为$和[]在引用数据框中的向量时起到同样的作用.

有人可以帮助我理解问题并使用[,]表达式将此向量转换为数字吗?

logic r vector dataframe

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