我正在尝试在自定义对象的ArrayList上使用Collections.sort,但我收到警告,我无法弄清楚为什么
Warning: Type safety: Unchecked invocation
sort(ArrayList<CharProfile>) of the generic method sort(List<T>)
of type Collections
Run Code Online (Sandbox Code Playgroud)
使用此代码:
ArrayList<CharProfile> charOccurrences = new ArrayList<CharProfile>();
...
Collections.sort(charOccurrences);
Run Code Online (Sandbox Code Playgroud)
这是我的方法:
public class CharProfile implements Comparable {
...
@Override
public int compareTo(Object o) {
if (this.probability == ((CharProfile)o).getProbability()) {
return 0;
}
else if (this.probability > ((CharProfile)o).getProbability()) {
return 1;
}
else {
return -1;
}
}
}
Run Code Online (Sandbox Code Playgroud) -4 & -5 = -8 // How?
-4 & 5 = 4 // How?
Run Code Online (Sandbox Code Playgroud)
我需要解释如何达到上述结果.我用正整数求解没有困难.
假设我有nodejs
serverProgram
一个 api,它对通过 http 请求发送的视频文件进行了一些操作。
const saveVideoFile=(req,res)=>{
processAndSaveVideoFile(); // can run for minimum of 10 minutes
res.send({status: "video is being processed"})
}
Run Code Online (Sandbox Code Playgroud)
我决定使用 aworkerThread
来做这个处理,因为我的机器有 3 个内核(core1、core2、core3)并且这里没有启用超线程
假设我的 nodejs 程序在core1
. 当我火了一个单一的WorkerThread,将在运行的WorkerThreadcore2/core3
还是core1
?
我读到 workerThread 与 childProcess 不同。ChildProcess 将派生一个新进程,这将有助于 childProcess 从可用的免费内核(core2 或 core3)中进行选择。
我读到 workerThread 与 mainThread 共享内存。假设我创建了 2 个 workerThreads (wt1,wt2)。我的 nodejs 程序 wt1、wt2 会在同一个核心上运行core1
吗?
此外,在 nodejs 中,我们有 eventloop(主线程)和 otherThreads 执行后台操作,即 I/O。假设所有这些都在利用单个内核 (core1) 中可用的资源是否正确。如果是这种情况,是否在 nodejs 服务器上创建和使用额外的 workerThread 是一种矫枉过正?
下面是这个博客 …
请解释为什么这种奇怪的行为发生在案例3中但不是案例4中.
public class InputBufferedReader {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
//1-start
//read one character
System.out.println("enter input: ");
int b= br.read();
System.out.println(b);
//end
//2-start
//read a string
System.out.println("enter input string: ");
String a = br.readLine();
System.out.println(a);
//end
} catch (IOException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)