我在 JavaScript 乘法中有一个奇怪的行为。我试图将数字乘以 100。例如:
> 9.5*100
> 950
> 9.95*100
> 994.9999999999999
> 9.995*100
> 999.4999999999999
> 9.9995*100
> 999.9499999999999
> 9.99995*100
> 999.995
> 9.999995*100
> 999.9995
> 9.9999995*100
> 999.9999499999999
> 9.99999995*100
> 999.9999949999999
> 9.999999995*100
> 999.9999995
> 9.9999999995*100
> 999.99999995
> 9.99999999995*100
> 999.999999995
> 9.999999999995*100
> 999.9999999995
> 9.9999999999995*100
> 999.9999999999501
> 9.99999999999995*100
> 999.999999999995
> 9.999999999999995*100
> 999.9999999999994
Run Code Online (Sandbox Code Playgroud)
我只想像这样将数字相乘
9.95*100
995.0 or 995
9.995*100
999.5
9.9995*100
999.95
9.9999995*100
999.99995
Run Code Online (Sandbox Code Playgroud)
而不是这样
> 9.995*100 …Run Code Online (Sandbox Code Playgroud) 我有一个返回函数引用的方法.
function methodetobeMoked(param){
case1:return func1;
case 2: return func2;
.
.
case n: return funcN;
}
Run Code Online (Sandbox Code Playgroud)
我需要窥探这个方法并为特定的输入参数p返回一个假的函数引用
在茉莉花测试中是否有任何条件调用我的情景是
SpyOn(some object,'someMethode').and.{if param=p callFake(fakeMethode) else callThrough()}我试过callFake有没有办法从伪方法将控制传递给原始方法?
我看过这篇文章
java:unchecked调用getConstructor(java.lang.Class <?> ...)
for (Map.Entry<String, Class> entry : connectionRepository.entrySet()) {
if (/*someconditionhere*/) {
try {
cwsConnection = (CWSConnection)entry.getValue().getConstructor().newInstance();
break;
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
logger.error("Could not Create instance of CWSConnection for site version:\"{}\" Error:\"{}\"", entry.getKey(), e.getMessage(), e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
编译这段代码时,我收到了警告
警告:[unchecked] unchecked调用getConstructor(Class ...)作为原始类型Class的成员
我只是想获得CWSConnection的默认构造函数,因此,我不应该将任何参数传递给getConstructor(Class ...)方法.有没有更好的方法来获取默认构造函数(没有参数的那个)
(我知道@SupressWarning注释会抑制此警告.)
我正在开发一个项目,其中我使用 firebase 工具(firebase CLI)以编程方式创建多个实时数据库。我正在使用以下命令创建一个新数据库。
firebase 数据库:实例:创建
。我还想为新创建的数据库应用自定义规则。我从firebase CLI 文档中找到了以下命令
firebase部署——仅数据库
我有点害怕使用这个命令,因为我没有提到要更新的数据库的名称。如果有人可以帮助我了解 firebase CLI 如何选择要更新的数据库,我将非常感激。
firebase firebase-tools firebase-realtime-database firebase-cli
这是 MacBook Pro 中的一个问题。经过几个小时的调试,我发现了这个问题
我正在使用以下代码创建媒体播放器并播放 mp3 文件。我在 Android Studio 中使用内置模拟器。有什么调试建议吗?
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mediaPlayer = MediaPlayer.create(this,R.raw.music);
mediaPlayer.start();
}
}
Run Code Online (Sandbox Code Playgroud)
活动_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ablejohnson.audiodemo.MainActivity">
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
编辑
为了进一步调试,我添加了一个 onErrorListener mediaPlayer
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
Log.e("error","what:"+what+",extra"+extra);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
以下行将打印在日志中。
D/Atlas: Validating map...
E/MediaPlayer: Should have subtitle …Run Code Online (Sandbox Code Playgroud)