老师这个Interator是接口还是接口定义的方法啊
创建对象时list调用的这个iterator又是个啥
老师这里创建迭代器对象不是很明白
//老师,如果在Account类中重写equals方法,使得当accountNo相同的情况下判定为同一对象 那为什么线程同步没有进行互斥呢 import java.util.Objects; class Account { private String accountNo; private double balance; @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Account account = (Account) o; return Double.compare(account.balance, balance) == 0 && Objects.equals(accountNo, account.accountNo); } @Override public int hashCode() { return Objects.hash(accountNo, balance); } public Account(String accountNo, double balance) { this.accountNo = accountNo; this.balance = balance; } public Account() { } public String getAccountNo() { return accountNo; } public void setAccountNo(String accountNo) { this.accountNo = accountNo; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } } class DrawThread extends Thread { //账户对象 private Account account; private double drawMoney; public DrawThread(String Name, Account account, double drawMoney) { super(Name); this.account = account; this.drawMoney = drawMoney; } @Override public void run() { synchronized (this.account){ //判断当前账户余额是否大于或等于取款金额 if (this.account.getBalance() >= this.drawMoney) { System.out.println(this.getName() + "取款成功!" + this.drawMoney); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } //更新账户余额 this.account.setBalance(this.account.getBalance() - this.drawMoney); System.out.println("当前余额为:" + this.account.getBalance()); } else { System.out.println(this.getName() + "取款失败,余额不足"); } } } } public class DrawMoneyDemo { public static void main(String[] args) { Account account = new Account("1001", 1000); Account account1 = new Account("1001", 1000); System.out.println(account1.equals(account)); new DrawThread("老公", account, 800).start(); new DrawThread("老妞", account1, 800).start(); } }
想问一个问题,我在写发送消息线程时,synchronized中的"abc".wait()会飘红,必须在catch中处理InterruptedException异常才行,但是视频中和其他提问的同学都没出现这个异常,想知道是怎么回事?
老师想问一下a与b完全没有交集的时候,差集会失败吗,会返回false吗
视频中的temp是什么意思老师
原来是找文件报的一个filenot异常 后来又是这个read异常 在方法声明里直接是IOException 是不是这个io异常直接覆盖了filenotexception了呢
不明白这里为什么要另外push右边的元素进去,不应该全部push字符串里面的元素进栈,然后再将出栈元素与从头开始扫描的str元素相比较,若不同则返回false吗?
我明白了,是多态,所以不能用子类独有方法。
老师,请问为什么第二个for-each会报错呢?内部类对象不是Object对象吗?
public class listTest2 { public static void main(String[] args) { Set<String> a = new HashSet<>(); a.add("aaa");a.add("bbb");a.add("ccc"); for(Object temp:a){ System.out.println(temp); } Map<String,Integer> m = new HashMap<>(); m.put("C",1);m.put("A",1);m.put("B",1); Set<Map.Entry<String,Integer>> b = m.entrySet(); for(Object temp:b){ System.out.print(temp.getKey()+"-----"+temp.getValue()); } } }
老师,先问一下为什么方法中传入参数可以直接传入对象吗?不需要调用该类吗?我以为只可以传入基本数据类型。(代码当中斜体的部分)
Generic1<> { (flag){ .=flag} (){ } } showmsg{ System..println(generic1.getFlag())} } Test11{ (String[]args){ Generic1<Number> generic1=Generic1<>()generic1.setFlag()showmsg showmsg=showmsg()showmsg.showFlag(generic1)Generic1<String> generic11=Generic1<>()generic11.setFlag()showmsg showmsg1=showmsg()showmsg1.showFlag(generic11)} }
老师想问一下定义一个数组的时候必须规定数组长度吗,那为什么在使用main方法时public static void main(String[]args){}; String 无需定义数组长度?还有想问一下以下两种定义方法有什么区别
老师,想问一下这个对象引用接口修饰时算父类引用指向子类对象吗,这里泛型是否只可以使用String类型。
IGeneric<> { (name)} TestGeneric IGeneric<String>{ String (String name) { name} } Test{ (String[] args) { TestGeneric generic=TestGeneric()String name=generic.name()System..println(name)IGeneric<String> generic1= TestGeneric()System..println(generic1.name())} }
老师,请问是数组可以自动转换,但不能强制抓转换吗?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637