0xCAFEBABE与Hexspeak
如果将Java源码编译后的class文件以16进制方式打开,会发现前4个字节都是0xCAFEBABE
。
如果将Java源码编译后的class文件以16进制方式打开,会发现前4个字节都是0xCAFEBABE
。
写代码无意中看到java.util.Random
中的nextInt(int bound)
方法, 有这么两行代码让我虎躯一震。
int m = bound - 1;
if ((bound & m) == 0) // i.e., bound is a power of 2
这就能检测一个数是不是2的幂了???
平时使用Spring少不了各种注入,大部分时候都是直接在属性上@Autowired就完了,偶尔看到在构造方法上注入的也知道怎么回事。今天忽然想到这俩有什么区别,了解了下使用场景。
在使用lambda的map时候看到了flatMap这个方法,之前知道和map不一样,但是一直没管它,这次又想起来,就找了点资料看了下。
用了spring-boot-starter-data-mongodb模块后,连接本机的Mongodb一直失败,用户也创建了,密码也设了,就是连不上啊。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
总是报错:
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='test', source='test', password=<hidden>, mechanismProperties={}}
at com.mongodb.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:162)
at com.mongodb.connection.SaslAuthenticator.access$200(SaslAuthenticator.java:39)
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:68)
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:46)
at com.mongodb.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:168)
at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:46)
at com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32)
at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:122)
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:52)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:127)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:164)
at com.mongodb.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:295)
at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255)
at com.mongodb.connection.CommandHelper.sendAndReceive(CommandHelper.java:84)
at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:34)
at com.mongodb.connection.SaslAuthenticator.sendSaslContinue(SaslAuthenticator.java:123)
at com.mongodb.connection.SaslAuthenticator.access$100(SaslAuthenticator.java:39)
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:65)
... 9 common frames omitted