首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Java构造函数没有正确编译

Java构造函数没有正确编译
EN

Stack Overflow用户
提问于 2018-12-06 05:45:34
回答 1查看 0关注 0票数 0

我是Java的新手,刚刚开始上课,所以仍然掌握一切是如何运作的,所以请在我尝试理解所有这些新材料时请耐心等待。

我的任务要求银行账户能够从支票和储蓄账户转账。交易存储在arraylist中并为用户设置以指定何时转移资金。用于检查和保存的银行帐户类工作正常但我创建的transferervice类在我正在使用的ide netbeans中没有正确编译。

我的教师重写了我的一些代码以帮助但它仍然无法编译,提示似乎没有修复错误。我得到的Transaction是抽象的,无法实例化。我不太清楚我能做些什么来解决这个错误,所以任何帮助都会非常感激。

代码语言:javascript
复制
import java.util.ArrayList;
import java.util.Date;
import javax.transaction.Transaction;

public class TransferService {
    private Date currentDate;
    private ArrayList<Transaction> completedTransactions;
    private ArrayList<Transaction> pendingTransactions;

    public void TransferService(){
        this.currentDate = new Date();
        this.completedTransactions = new ArrayList<Transaction>();
        this.pendingTransactions = new ArrayList<Transaction>();
    }   

    public TransferService(BankAccount to, BankAccount from, double amount, Date when) throws InsufficientFundsException(){
        if (currentDate.after(when)){
            try(
            from.withdrawal(amount);
            to.deposit(amount);
            completedTransactions.add(new Transaction(to, from, this.currentDate, Transaction.TransactionStatus.COMPLETE));
            } catch (InsufficientFundsException ex){
                throw ex;
            }
        } else {
            pendingTransactions.add(new Transaction(to, from, null, Transaction.TransactionStatus.PENDING));
        }
    }

    private static class InsufficientFundsException extends Exception {

        public InsufficientFundsException() {
            System.out.println("Insufficient funds for transaction");
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2018-12-06 15:42:34

构造函数没有返回类型。所以没有

代码语言:javascript
复制
// this is a "pseudo"-constructor
public void TransferService(){

反而

代码语言:javascript
复制
// this is the real deal
public TransferService(){

关于,

事务是抽象的,无法实例化

好吧,是吗?Transaction类是抽象类还是接口?只有拥有代码的人知道答案。如果是这样,那么您需要在代码中使用Transaction的具体实现。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档