public class AplotPdfPrintLocal extends ApplicationWindow {
private String userSelectedFile;
public AplotPdfPrintLocal(String pdfFilePath) {
super(null);
this.userSelectedFile = pdfFilePath;
}
public void run() {
setBlockOnOpen(true);
open();
Display.getCurrent().dispose();
}
etc........
我想从B类执行上面的类
方法是 B 类 - 下面
public void startPDFPrint() throws Exception {
AplotPdfPrintLocal pdfPrint = new AplotPdfPrintLocal(getPDFFileName()).run();
}
我收到一个错误,需要将运行的返回类型从 void 更改为plotPdfPrintLocal
我会不会把这个类称为错误的?
最佳答案
将其更改为:
public void startPDFPrint() throws Exception {
AplotPdfPrintLocal pdfPrint = new AplotPdfPrintLocal(getPDFFileName());
pdfPrint.run();
}
或
public void startPDFPrint() throws Exception {
new AplotPdfPrintLocal(getPDFFileName()).run();
}
编译器所说的是,您试图将 run 方法的结果 (void) 分配给表达式的左侧成员,即 AplotPdfPrintLocal pdfPrint 变量.
因此,由于 run 正在“返回”void,因此存在错误,与预期的 AplotPdfPrintLocal 类型之间存在差异(在左侧声明)和实际返回类型:void。
关于java - 我如何从B类执行A类的run方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13352868/