以下类有一个名为的内部类Entry.此代码不会在Java 8中编译,因为编译器假定Entry双花括号初始值设定项中的引用是类型Map.Entry而不是Scope.Entry.这段代码在JDK的先前版本(至少6和7)中编译,但在JDK 8中被破坏.我的问题是"为什么?" Map.Entry未在此类中导入,因此编译器没有理由假设该值是类型Map.Entry.是否有一些隐含的范围被引入或匿名类的东西?
错误:
scope/Scope.java:23: error: incompatible types: scope.Scope.Entry cannot be converted to java.util.Map.Entry for (final Entry entry : entries) {
scope/Scope.java:22: error: cannot find symbol put(entry.getName(), entry);
Run Code Online (Sandbox Code Playgroud)
示例代码:
package scope;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
public class Scope {
public static class Entry<T> {
public String getName() {
return "Scope";
}
}
public static void main(String[] args) {
final Set<Entry> entries = new HashSet<>();
new HashMap<String, …Run Code Online (Sandbox Code Playgroud) 我注意到,前4个版本f6182e5abf5e,b66d0bf8da3e,ac3363d7e788,172d32922e72围棋源都来自很久以前Golang甚至提出,从1972年的最古老的存在.他们也都归功于AWK成名的Brian Kernighan.它们似乎是hello, worldC 中的实现.这是复活节彩蛋还是有一些实际目的?
我知道会话不是线程安全的.我的第一个问题:将实体传递给另一个线程,对它做一些工作,然后将其传递回原始线程并更新是安全的.
public class Example1 {
MyDao dao;
...
public void doWork() {
MyEntity entity = dao.getEntity();
Runnable job = new Job(entity);
Thread t = new Thread(job);
t.run();
t.join();
dao.merge(entity);
}
}
Run Code Online (Sandbox Code Playgroud)
我的第二个问题:在一个线程中新建一个实体并将其保存在另一个线程中是否安全?
public class Example2 {
MyDao dao;
...
public void doWork() {
MyEntity entity = new Entity();
new Thread(new Job(dao, entity)).run();
}
}
public class Job implements Runnable {
private MyDao dao;
private MyEntity entity;
...
@Override
public void run() {
dao.save(entity);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑我忘了提到实体是专门为急切加载配置的
当cmd在指定的时间内完成时,以下工作正常.但是,超时不起作用.虽然它确实打印"It's dead Jim",但它不仅无法打印"Done waiting",而且该过程实际上并未被杀死.它继续运行,"Done waiting"从不打印.
我认为这是所有相关的代码,但我是Go的新手(这是我尝试过的第一个真正的项目)所以如果这还不够,请告诉我.
func() {
var output bytes.Buffer
cmd := exec.Command("Command", args...)
cmd.Dir = filepath.Dir(srcFile)
cmd.Stdout, cmd.Stderr = &output, &output
if err := cmd.Start(); err != nil {
return err
}
defer time.AfterFunc(time.Second*2, func() {
fmt.Printf("Nobody got time fo that\n")
if err := cmd.Process.Signal(syscall.SIGKILL); err != nil {
fmt.Printf("Error:%s\n", err)
}
fmt.Printf("It's dead Jim\n")
}).Stop()
err := cmd.Wait()
fmt.Printf("Done waiting\n")
}()
Run Code Online (Sandbox Code Playgroud)
我不认为它应该有所作为,但对于命令的价值而言go test html.超时的原因是因为我在运行它之前注入了导致无限循环的错误.为了增加混乱,我试着运行它go test net.有一个超时,它工作正常.
我刚刚开始使用NERDtree和VIM,并且无法弄清楚如何使NERDtree 在打开时不是默认窗口.
我想在一个窗格中打开NERDTree,在另一个窗格中打开相关文件,但是当它打开时,不是让NERDTree选项卡获得焦点,而是让我按默认焦点编辑文件.
我查看了github项目,但是对于我来说,如何改变它的行为并不明显.其他一切都很完美.
是否有配置指定VIM启动时要关注哪个窗口,或者这是否需要设置NERDtree特定配置?
编辑:
相关.vimrc配置:
" Open Nerdtree automatically
autocmd vimenter * NERDTree
" Close Nerdtree if no files specified
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" Nerdtree behavior
map <C-n> :NERDTreeToggle<CR>
let NERDTreeHighlightCursorline=1
Run Code Online (Sandbox Code Playgroud) 默认情况下,终端缓冲区回滚大小设置为1024,但这对我来说还不够,我想更改它.
help terminal 没有解释如何配置它.
我正在尝试实现一个玩具搜索算法,并且需要维护一组已探索的状态。状态是一个结构体:
type VWState struct {
botLocation VWCoords
dirtLocations []VWCoords
}
Run Code Online (Sandbox Code Playgroud)
我的第一个想法是可以使用 a 来实现一个简单的 Set map[VWState]bool,但我似乎无法找到使其工作的方法。如果我尝试使用 aVWState作为地图的键,我会收到以下恐慌:
Panic: runtime error: hash of unhashable type vw.VWState (PC=0x40EB0D)
Run Code Online (Sandbox Code Playgroud)
有办法让这项工作发挥作用吗?我可以为该结构实现自定义哈希函数,还是应该考虑其他一些方法来实现它?
任何帮助将不胜感激。
无法使用JDK 8,glassfish 4.1在eclipse Luna上部署Glassfish.jsp.
异常堆栈跟踪:
org.glassfish.tools.ide.admin.CommandException: Cannot initialize Runner class
at org.glassfish.tools.ide.admin.AdminFactory.newRunner(AdminFactory.java:180)
at org.glassfish.tools.ide.admin.AdminFactoryHttp.getRunner(AdminFactoryHttp.java:110)
at org.glassfish.tools.ide.admin.ServerAdmin.exec(ServerAdmin.java:75)
at oracle.eclipse.tools.glassfish.GlassfishServerBehaviourDelegate.publishDeployedDirectory(GlassfishServerBehaviourDelegate.java:608)
at oracle.eclipse.tools.glassfish.GlassfishV4ServerBehavior.publishModuleForGlassFishV3(GlassfishV4ServerBehavior.java:96)
at oracle.eclipse.tools.glassfish.GlassfishV4ServerBehavior.publishModule(GlassfishV4ServerBehavior.java:56)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModule(ServerBehaviourDelegate.java:1091)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publishModules(ServerBehaviourDelegate.java:1183)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:987)
at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:774)
at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:3157)
at org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:345)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Run Code Online (Sandbox Code Playgroud)
会话数据:
eclipse.buildId=4.4.1.M20140925-0400
java.version=1.8.0_25
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=es_MX
Framework arguments: -product org.eclipse.epp.package.jee.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product
Run Code Online (Sandbox Code Playgroud) 我能够使用 创建过滤器链http.oauth2ResourceServer().jwt()并且我还设置了spring.security.oauth2.resourceserver.jwt.issuer-uri. 它能够验证请求。但是,我还需要在身份验证失败的情况下进行自定义日志记录。我采用的方法是使用自定义身份验证入口点来处理不存在持有者令牌的情况,并结合自定义BearerTokenAuthenticationFilter.authenticationFailureHandler来处理无效令牌。我愿意接受其他方法来实现这一目标。
我可以配置自定义身份验证入口点来处理不存在令牌的情况:
// in WebSecurityConfigurerAdapter::configure
http
.exceptionHandling()
.authenticationEntryPoint((request, response, exception) -> { /* ... */ });
Run Code Online (Sandbox Code Playgroud)
但是我还没有找到访问 BearerTokenAuthenticationFilter 的方法。我能想到的最好的办法就是按照我想要的方式新建第二个配置,但这对我来说没有吸引力,因为服务器最终会对每个成功验证的请求执行额外的工作:
// in WebSecurityConfigurerAdapter::configure
var filter = new BearerTokenAuthenticationFilter(authenticationManagerBean());
filter.setAuthenticationFailureHandler(new JwtAuthenticationFailureHandler());
http.addFilterBefore(tokenAuth, BearerTokenAuthenticationFilter.class);
// my filter runs first
Run Code Online (Sandbox Code Playgroud)
当然有某种方法可以在 Spring Security 创建的过滤器中设置此属性吗?理想情况下,它会被暴露出来OAuth2ResourceServerConfigurer,但这只是提供accessDeniedHandler。
我尝试过以 bean 的形式访问过滤器本身或 DefaultSecurityFilterChain,但它们在应用程序上下文中不以 bean 形式存在。我发现这个答案建议配置一个beanspring-servlet.xml并通过后处理器运行它。BeanPostProcessor 的想法对我来说似乎很有希望,但我无法让它工作,因为按照建议修改后,spring-servlet.xmlbean 仍然不存在。我无法使用getBean它来找到它,并且它也没有被以下人看到BeanPostProcessor:
<http name="filterChain">
Run Code Online (Sandbox Code Playgroud)