我已经完成了这个线程是什么原因以及NoClassDefFoundError和ClassNotFoundException之间有什么区别? 这是一个在线程中具有max ups的ans之一: NoClassDefFoundError:"因此,当源成功编译时,似乎会发生 NoClassDefFoundError ,但是在运行时,找不到所需的类文件.这可能是在分发或生成JAR文件时可能发生的事情,其中并未包含所有必需的类文件."
ClassNotFoundException:对于ClassNotFoundException,它似乎可能源于尝试在运行时对类进行反射调用,但程序试图调用的类不存在.
我做了一个小实验.我创建了一个主类,类A,并尝试从中调用其他类,类B,编译成功.
然后我删除了在类A中调用的类B.我得到了 java.lang.ClassNotFoundException但是根据脚步中的答案,我应该得到NoClassDefFoundError(源代码已成功编译,但未找到运行时类文件)任何人都可以解释我在线程中对ans的解释中缺少什么?
package com.random;
public class A {
public static void main(String[] args) {
B b= new B();
}
}
package com.random;
public class B {
}
Run Code Online (Sandbox Code Playgroud) 我一直在尝试了解取消订阅(useEffect 中的回调)何时被准确调用。
这是codepen链接:https ://codepen.io/deen_john/pen/eYmNdMy 代码:
const { useState, useEffect } = React ;
function App() {
const [count, setCount] = useState(0);
// Similar to componentDidMount and componentDidUpdate:
useEffect(() => {
// Update the document title using the browser API
document.title = `You clicked ${count} times`;
console.log("use effect called ");
return () => {
console.log("unsubscribe ")
}
});
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
ReactDOM.render(<App />, document.getElementById('root')) …Run Code Online (Sandbox Code Playgroud)我从Jest单元测试开始。运行笑话单元测试时,我一直收到“未找到测试”的信息。
错误说明
yarn test
yarn run v1.3.2
$ jest
No tests found
In E:\Course\Testing JavaScript\Jest Demo
4 files checked.
testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 3 matches
testPathIgnorePatterns: \\node_modules\\ - 4 matches
Pattern: - 0 matches
error Command failed with exit code 1.
Run Code Online (Sandbox Code Playgroud)
os:窗口7,节点v:8.6,npm v:5.4.2
folder structure :
Demo
package.json
__tests__
sum.js
sum.test.js
Run Code Online (Sandbox Code Playgroud)
sum.js文件:
function sum(a, b) {
return a + b;
}
module.exports = sum;
Run Code Online (Sandbox Code Playgroud)
sum.test.js
const sum = require("./sum");
test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3); …Run Code Online (Sandbox Code Playgroud) 我浏览了String和StringBufferAPI,当您调用该substring方法时,两者在内部的工作方式似乎相同。两者都有对原始字符数组 ( char[] original)的引用,因此两者都使用相同的空间。那为什么是StringBuffer首选呢?那么 stringbuffer.substring(2,4) 与 string.substring(2,4) 有何不同。
StringBuffer 的子串方法:
public String substring(int start, int end) {
return new String(value, start, end - start);
}
Run Code Online (Sandbox Code Playgroud)
字符串的子串方法:
public String substring(int beginIndex, int endIndex) {
return ((beginIndex == 0) && (endIndex == value.length)) ? this
: new String(value, beginIndex, subLen);
}
Run Code Online (Sandbox Code Playgroud)
两个子字符串变体然后调用 String 构造函数:
public String(char value[], int offset, int count) {
this.value = Arrays.copyOfRange(value, offset, offset+count);
}
Run Code Online (Sandbox Code Playgroud)
它调用以下 Arrays 类的方法:
public static …Run Code Online (Sandbox Code Playgroud) 逻辑很简单 - 遍历根以后期顺序结束,然后使节点为空.下面是我为删除树的所有节点而编写的代码(即删除二叉树).
问题:未删除实际树.我的意思是deleteTree(BTNode root)函数只将null ref的所有值都归零,而不是head的值.
tree.preorder();
tree.deleteTree();
tree.preorder();- this still prints all values of a tree
Run Code Online (Sandbox Code Playgroud)
即使在执行tree.deleteTree()之后,它也会打印树中的所有节点.
有人可以帮我解决代码中的错误吗?
注意:插入和预订功能没有错误.因此,您可以专注于deleteTree()代码
package com.practice;
import java.util.LinkedList;
public class BinaryTree {
private BTNode head;
public void insert(int data){
BTNode n= new BTNode (data);
BTNode temp=null;
if(head==null){
head=n;
return;
}
else{
LinkedList q= new LinkedList();
q.addLast(head); //enque
while(!q.isEmpty()){
temp=(BTNode) q.removeFirst();
if( temp.getLeft() ==null){
temp.setLeft(n);
return;
}
else{
//enque
q.addLast( temp.getLeft());
}
if( temp.getRight() ==null){
temp.setRight(n);
return;
}
else{
//enque
q.addLast( temp.getRight());
}
}//while …Run Code Online (Sandbox Code Playgroud) 为什么我不能head=null删除完整的链接列表?
3 = head > 1 > 2 > 4 > null
Run Code Online (Sandbox Code Playgroud)
通过制作head = null,JVM将负责它.由于头节点没有被任何变量引用,它应该被垃圾收集.
这个解决方案有什么问题?
注意:我知道删除完整链接列表的正确解决方案,但我很好奇为什么我不能head=null删除完整的链表?
java ×4
binary-tree ×1
exception ×1
javascript ×1
jestjs ×1
linked-list ×1
react-hooks ×1
reactjs ×1
string ×1
stringbuffer ×1
substring ×1
unit-testing ×1