我试图创建一个更快版本的String.equals()方法,并通过简单地复制它开始.我发现的结果非常令人困惑.当我运行复制粘贴版本,定时并将其与JVM版本进行比较时,JVM版本更快.差异从6倍到34倍不等!简单地说,字符串越长,差异就越大.
boolean equals(final char a[], final char b[]) {
int n = a.length;
int i = 0;
while (n-- != 0) {
if (a[i] != b[i]) return false;
i++;
}
return true;
}
public static void main() throws Exception {
String a = "blah balh balh";
String b = "blah balh balb";
long me = 0, jvm = 0;
Field value = String.class.getDeclaredField("value");
value.setAccessible(true);
final char lhs[] = (char[]) value.get(a);
final char rhs[] = (char[]) value.get(b);
for (int …Run Code Online (Sandbox Code Playgroud) 我使用VS 2015.当我创建一个新类并尝试使用快捷键"Ctrl +"实现一个接口.例如,StarShip类:IStarShip然后我使用"Ctrl +".并选择工具界面.它按字母顺序实现属性和方法!是否有一种简单的方法可以按照它们在界面中的顺序实现它们,还是应该手动执行?我仍然没有resharper,所以这不是一个选择.
我最近发现在我看来是静态初始化ArrayList的新语法:
new ArrayList() {{
add("first");
add("second");
}};
我的问题是,那里到底发生了什么?这是定义静态块的快捷方式(我认为它需要static关键字)?或者只是一种定义默认构造函数的方法?别的什么?哪个版本的Java有效?
将非常感谢解释以及进一步阅读的链接.
编辑:我的测试类,用于显示初始化程序块是否在构造函数之前或之后执行.结果显示初始化程序块在其他构造函数代码之前执行:
import org.junit.Test;
public class InitializerBlockTest {
class InitializerTest {
{
System.out.println("Running initalizer block");
}
public InitializerTest() {
System.out.println("Running default constructor");
}
}
class SubClass extends InitializerTest {
{
System.out.println("Running subclass Initializer block");
}
public SubClass() {
System.out.println("Running subclass constructor");
}
}
@Test
public void testIt() {
new SubClass();
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
Running initalizer block
Running default constructor
Running subclass Initializer block
Running subclass constructor
Run Code Online (Sandbox Code Playgroud) 我有 8 个cucumber-jvm场景,第一个场景测量页面加载时间和环境可用性。为了避免不必要的运行,如果第一个场景失败 - 例如,环境不可用或加载太慢 - 应跳过所有其他场景。
我怎样才能做到这一点?
我的CucumberOptions:
@RunWith(Cucumber.class)
@CucumberOptions(
strict = true,
features = {"src/test/resources/features"},
glue = {"stepDefinitions"},
format = { "progress", "html:target/Results",
"json:target/Results/cucumber.json"},
tags = {"@test"})
public class TestRunner {
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
是否有通过使用索引删除存储在JSONArray中的JSONObject的直接方法.我尝试了所有的可能性.仍然无法从JSON数组中删除JSON对象.任何提示都会有所帮助谢谢
将Chrome更新到最新版本后,我不断收到此InvalidOperationException.我在c#中使用Selenium-Webdriver
System.InvalidOperationException: disconnected: unable to connect to renderer
(Session info: chrome=62.0.3202.62)
(Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 6.1.7601 SP1 x86_64) (102)
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWindow.Maximize()
Run Code Online (Sandbox Code Playgroud) 为了庆祝Pi Day,我决定采用Monte Carlo方法近似计算?的值。,但是我的算法似乎无效。
我尝试使用不同的参数运行,但总能获得约3.66的效果
我已经尝试调试,但无法弄清楚。
public class ApproximatePi {
private int iterations; // how many points to test
private double r; // width of the square / radius of circle (quarter circle)
private int inCount = 0; // number of points that are inside the circle
private int outCount = 0; // number of points outside of the circle
private Random getNum = new Random(System.currentTimeMillis());
ApproximatePi(int iterations, double r) {
this.iterations = …Run Code Online (Sandbox Code Playgroud) 我正在构建一个Web服务客户端,以便与一个(基于java的)远程Web服务进行交互,这是我无法控制的.我可以调用Web服务操作,并通过数据包嗅探告诉服务正在响应填充的数据.但是,当响应进入客户端代码时,响应只是一个shell,所有数据都为null.
我怀疑在Web服务"管道"中发生了一个错误,导致数据被静默删除或忽略,但我找不到一种方法来启用调试(甚至日志或错误消息?)在它命中我的客户端代码之前的响应.
我的App.config启用了消息日志记录,但只记录了外发消息:
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="messages"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\messages.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="3000"
maxSizeOfMessageToLog="2000"/>
</diagnostics>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我真的想在实际解析响应消息期间设置断点,但让Message Logger实际记录响应也可能有所帮助.
我还配置了一个自定义MessageEncoder,它是解决远程服务解析器中的错误所必需的.我可以在这个ReadMessage方法上添加断点MessageEncoder,并且可以看到数据在那时仍然存在.但是,下一步跳回到客户端代码,并且Response对象为空 - 没有警告或消息.有什么方法可以看到两者之间发生了什么?
所以,我想这最终是一个由两部分组成的问题:
MessageEncoder,但在它被发送到客户端代码之前?我出现的唯一错误是在那个类中找不到getName()和getSalary().我试图获取输入testEmployee类的信息以使用Employee并显示结果.我收到Build Successful消息但没有输出.
public abstract class Person {
// Variables
private String name;
private String ssn = null;
public Person(String name) {
this.name = name;
}
// Pass data to the object Person
/**
*
* @param ssn
*/
public void setSsn(String ssn) {
this.ssn = ssn;
}
public String getSsn() {
return ssn;
}
/**
*
* @return
*/
public abstract String getName();
}
class Employee extends Person {
// Variables
private String jobTitle;
private double salary;
private String getName; …Run Code Online (Sandbox Code Playgroud) 我还是 Angular 4 的新手(使用 Angular-CLI)。我不知何故无法获得简单的 Bootstrap Collapse 工作。
以下是我的崩溃代码:
<div *ngFor="let idea of ideas" class="panel panel-default">
<div class="panel-heading">{{ idea.title }}</div>
<div class="panel-body">
<cite>{{ idea.author }}</cite>
<p>{{ idea.description }}</p>
<button type="button" class="btn btn-primary" data-toggle="collapse" [attr.data-target]="'#'+idea._id" aria-expanded="false" [attr.aria-controls]="idea._id">More</button>
</div>
<div [attr.id]="idea._id" class="collapse"><p>Show Details</p></div>
</div>
Run Code Online (Sandbox Code Playgroud)
更新:
我确实导入了所有相关的 Bootstrap 和 jQuery 脚本。正如您在下面看到的,ID 确实匹配。我不知道为什么它不起作用?Angular 5 和 Bootstrap 的折叠是否存在问题?
在"划拳"教程例子(在这里),我的编译器是给下面的错误,我解释为,expect不上不存在read_line的Result.
error: type `core::result::Result<usize, std::io::error::Error>` does not implement any method in scope named `expect`
Run Code Online (Sandbox Code Playgroud)
违规代码:
use std::io;
fn main() {
println!("**********************");
println!("***Guess the number***");
println!("**********************");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line"); //<<-- error on this line
//let guess_result=io::stdin().read_line(&mut guess);
println!("You guessed: {}", guess);
// println!("Result: {}", guess_result.is_ok());
}
Run Code Online (Sandbox Code Playgroud)
我可以删除行,.expect()并使用上面的注释行并使其工作.我担心的是,它看起来像结果类型由io::stdin().read_line是core::result::Result而不是std::io::Result在本教程中提到.
如果我在Rust操场上运行相同的代码,它似乎运行正常,所以它可能在我的环境中,但我不能想到它可能是什么.
其他可能相关的信息:
rust-1.0.0-x86_64-pc-windows-gnu.msiPATH