在处理Java项目时,我遇到了如下所示的代码:
someMap.keySet().stream().sorted().forEach(/* ... */);
Run Code Online (Sandbox Code Playgroud)
根据键的自然顺序,这里的意图显然是为地图中的每个键做一些事情,这似乎是在实践中发生的事情.但是,我不确定这种行为是否得到保证.Javadoc for Stream#forEach说:
此操作的行为明确是不确定的.对于并行流管道,此操作不保证遵守流的遭遇顺序,因为这样做会牺牲并行性的好处.对于任何给定元素,可以在任何时间以及库选择的任何线程中执行该动作.
我知道如果代码使用.parallelStream()而.stream()不是保证它不能保证工作,但由于它使用的是顺序流(Javadoc没有说什么),我不确定.这是保证始终有效,还是代码需要使用.forEachOrdered()而不是.forEach()它?
编辑:我认为这个问题不是Java 8 Stream中forEach vs forEachOrdered的重复,因为这个问题是"一般来说forEach和forEachOrdered之间有什么区别的例子",并且接受的答案基本上是"并行流" .这个问题具体是关于顺序流.
我正在请求 android studio 中相机的权限,但它在 Manifest.permission.CAMERA 上引发了错误
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.CAMERA},REQUEST_CAMERA);
Run Code Online (Sandbox Code Playgroud)
我试图Foreign.C.Types在Haskell中使用C调用Haskell,但它在编译器中始终显示此错误:
Run Code Online (Sandbox Code Playgroud)* Unacceptable argument type in foreign declaration: `(CInt, CInt)' cannot be marshalled in a foreign call * When checking declaration: foreign export ccall "func_hs" func_hs :: (CInt, CInt) -> CInt | 15 | foreign export ccall func_hs :: (CInt, CInt) -> CInt | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
GHCi版本8.6.3编译的确切代码:
{-# LANGUAGE ForeignFunctionInterface #-}
module Func where
import Foreign.C.Types
verify_hp :: (CInt, CInt) -> CInt
verify_hp (hp, maxHp) = if hp < maxHp then hp + 10 else maxHp
func_hs :: (CInt, …Run Code Online (Sandbox Code Playgroud) 当我调用该any()函数时,它只返回Trueor False。如果它返回True,我怎样才能获得导致它返回的元素True?
all = ['azeri', 'english', 'japan', 'india', 'indonesia']
lg = 'from japan'
lgn = lg.split()
if any(word in lgn for word in all):
print(word)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我想获得单词japan. 这段代码,如所写,只是返回NameError: name 'word' is not defined.
我有一个数据类型和伴随函数,看起来非常像某种遍历。这是一个简化的示例:
data Foo x = MkFoo (Bar x) (Bar x)
almostTraverse :: Applicative f => (Bar a -> f (Bar b)) -> Foo a -> f (Foo b)
almostTraverse f (MkFoo x y) = MkFoo <$> f x <*> f y
Run Code Online (Sandbox Code Playgroud)
假定这Bar是某种不透明类型,并且不一定是函子。是否有某种类型化的泛化almostTraverse?它不是otraversefrom的MonoTraversable,因为应用程序内部的结果类型不必与输入类型完全相同,也不traverse是Traversable二者之一,因为传入的函数Bar尽管不在type参数中,但也需要知道。
我正在尝试在 macOS 上的 eclipse 中制作一个 smimple mod,一切正常,直到我将纹理 .png 文件添加到游戏中,然后出现 DS_Store 错误,我几乎每一次都查看了有关此问题的内容,但没有任何效果,我知道您可以停止在 NAS 上创建 DS_Store 而不是在本地,我可以做些什么来解决这个问题?
[m[32m[23:15:59] [Forge Version Check/INFO] [ne.mi.fm.VersionChecker/]: [forge] Found status: BETA Current: 30.0.51 Target: 30.0.51
[m[32m[23:15:59] [Forge Version Check/INFO] [ne.mi.fm.VersionChecker/]: [testmod] Starting version check at http://myurl.me/
[m[33m[23:16:00] [Forge Version Check/WARN] [ne.mi.fm.VersionChecker/]: Failed to process update information
java.io.IOException: Server returned HTTP response code: 400 for URL: http://myurl.me/
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_231] {}
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_231] {}
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_231] {}
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_231] {}
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1950) ~[?:1.8.0_231] {} …Run Code Online (Sandbox Code Playgroud) 我的印象是,Linux 内核试图保护自己的核心是不让恶意代码在内核空间中运行。特别是,如果要加载恶意内核模块,从安全角度来看,这将是“游戏结束”。然而,我最近看到一篇与这种观点相矛盾的帖子,并说内核可以通过某种方式保护自身的一部分免受自身其他部分的影响:
有很多机制可以保护您免受恶意模块的侵害。我写内核代码是为了好玩,所以我在这个领域有一些经验;它基本上是页表中的一个标志。
有什么可以阻止任何内核模块更改分页表中的那个标志?防止恶意模块的唯一保护是完全阻止它们加载。一旦加载,游戏就结束了。
使分页表只读。完毕。
内核模块可以再次将其设为可读写,就像您的代码将其设为只读一样,然后继续进行更改。
您实际上可以将其锁定,以便内核模式在发生中断之前无法修改页表。如果您的 IDT 也是只读的,则模块无法对其进行任何处理。
这对我来说没有任何意义。我是否遗漏了一些关于内核内存如何工作的重要信息?内核空间代码可以限制自己修改页表吗?这真的能阻止内核 rootkit 吗?如果是这样,那么为什么今天的 Linux 内核不这样做以结束所有内核 rootkit?
我试图通过检查空字符串 ("") 来终止我的 C 程序,但它似乎不起作用。我也尝试与 "\0" 进行比较,但无济于事。
#include <stdio.h>
#include <string.h>
int main(void) {
char nameInput[128];
for(;;) {
printf("Enter nation name: ");
scanf("%s", nameInput);
if(!strcmp(nameInput, "")){
break;
}
printf("Got nation named \"%s\"\n", nameInput);
}
printf("All done getting nations!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 GHC 9.2.1 上安装 aeson。我第一次运行cabal install --allow-newer --lib aeson,在构建 attoparsec 时失败了。事实证明这个问题已经在他们的 Git repo 中得到了修复,但还没有在 Hackage 上发布。然后,我执行了以下步骤来构建包含修复程序的本地版本:
git clone https://github.com/haskell/attoparsec.git
cd attoparsec
cabal install --allow-newer --lib .
cd ..
Run Code Online (Sandbox Code Playgroud)
成功了,但是当我cabal install --allow-newer --lib aeson再次这样做时,它再次尝试从 Hackage 构建 attoparsec,所以再次失败。我怎样才能让阴谋集团使用我刚刚构建和安装的东西呢?
当我编写一个要与 一起使用的库时LD_PRELOAD,如何调试它的__attribute__((__constructor__))功能?它们似乎总是在 GDB 停止进程之前运行。作为 MCVE,运行以下命令:
cat > preflight.c <<EOF
#include <stdio.h>
#include <stdlib.h>
__attribute__((__constructor__))
void preflight(void) {
puts("Exiting from preflight");
exit(42);
}
EOF
gcc -g -fPIC -shared preflight.c -o preflight.so
gdb /bin/true -ex 'set environment LD_PRELOAD ./preflight.so' \
-ex 'set breakpoint pending on' \
-ex 'break preflight' \
-ex 'starti'
Run Code Online (Sandbox Code Playgroud)
GDB 输出的末尾将如下所示:
Function "preflight" not defined.
Breakpoint 1 (preflight) pending.
Starting program: /usr/bin/true
Exiting from preflight
During startup program exited with code 42.
(gdb)
Run Code Online (Sandbox Code Playgroud)
观察到该preflight …
c ×3
haskell ×3
java ×3
any ×1
assembly ×1
c-strings ×1
cabal ×1
control-flow ×1
debugging ×1
eclipse ×1
gdb ×1
java-stream ×1
ld-preload ×1
linux-kernel ×1
list ×1
macos ×1
minecraft ×1
page-tables ×1
python ×1
python-3.x ×1
security ×1
traversal ×1
typeclass ×1
types ×1
x86-64 ×1