在java中,我们可以使用双重Checked Locking&volatile编写thead-safe单例:
public class Singleton {
private static volatile Singleton instance;
public static Singleton getInstance(String arg) {
Singleton localInstance = instance;
if (localInstance == null) {
synchronized (Singleton.class) {
localInstance = instance;
if (localInstance == null) {
instance = localInstance = new Singleton(arg);
}
}
}
return localInstance;
}
}
Run Code Online (Sandbox Code Playgroud)
我们怎么能用kotlin写呢?
object A {
object B {}
object C {}
init {
C.hashCode()
}
}
Run Code Online (Sandbox Code Playgroud)
我使用kotlin反编译器来实现
public final class A {
public static final A INSTANCE;
private A() { …Run Code Online (Sandbox Code Playgroud) 我在不同的布局中有两个视图,我想将它们移动到另一个.我的代码出了什么问题?Y动画播放错误.第一个视图位于片段的布局中,第二个视图位于状态栏中
...
int p1[] = new int[2];
int p2[] = new int[2];
viewOne.getLocationInWindow(p1);
viewTwo.getLocationInWindow(p2);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet
.play(ObjectAnimator.ofFloat(expandedImageView, "X", p1[0], p2[0] - p1[0]))
.with(ObjectAnimator.ofFloat(expandedImageView, "Y", p1[1], p2[1] - p1[1]))
.with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale))
.with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale));
Run Code Online (Sandbox Code Playgroud) gradle同步时出现此错误。我在android defaultConfig块中调用该方法。我使用com.android.tools.build:gradle:1.3.0 com.neenbedankt.gradle.plugins:android-apt:1.4
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: 'config.gradle'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
allprojects {
repositories {
jcenter()
}
}
Run Code Online (Sandbox Code Playgroud)
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
plugins {
id "me.tatarka.retrolambda" version "3.2.2"
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
repositories {
jcenter()
mavenCentral()
}
def googlePlayServiceVersion = "8.1.0"
def supportVersion = …Run Code Online (Sandbox Code Playgroud) 我需要清晰的 QT 控制台。什么是命令?
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cout<<"How delete this?";
//system("CLS")?
return a.exec();
}
Run Code Online (Sandbox Code Playgroud) 我尝试制作静态qt,并在mingw-make期间出错.这是错误的文本.
static\qhttpnetworkreply.o access\qhttpnetworkreply.cpp
In file included from ..\..\mkspecs\win32-g++/qplatformdefs.h:56:0,
from access\qhttpnetworkreply_p.h:55,
from access\qhttpnetworkreply.cpp:42:
c:\mingw\include\io.h:301:14: error: 'off64_t' does not name a type
__CRT_INLINE off64_t lseek64 (int, off64_t, int);
^
c:\mingw\include\io.h:302:14: error: 'off64_t' does not name a type
__CRT_INLINE off64_t lseek64 (int fd, off64_t offset, int whence) {
^
Makefile.Debug:8214: recipe for target '.obj/debug_static/qhttpnetworkreply.o' f ailed
mingw32-make[3]: *** [.obj/debug_static/qhttpnetworkreply.o] Error 1
mingw32-make[3]: Leaving directory 'C:/Qt/Qt5.1.1/5.1.1/Src/qtbase/src/network'
Makefile:38: recipe for target 'debug-all' failed
mingw32-make[2]: *** [debug-all] Error 2
mingw32-make[2]: Leaving directory 'C:/Qt/Qt5.1.1/5.1.1/Src/qtbase/src/network'
Makefile:182: recipe for …Run Code Online (Sandbox Code Playgroud) 在研究lambda期间,我希望list按第二个元素(int)排序.这个使用的代码.
#include <iostream>
#include <algorithm>
#include <list>
using namespace std;
int main()
{
list<pair <string, int>> s = {{"two", 2}, {"one", 1}, {"three", 3}};
sort(s.begin(), s.end(), [](pair<string,int> a, pair<string,int> b) -> bool
{
return (a.second) > (b.second);
}
);
for_each(s.begin(),s.end(),[](pair<string,int> a)
{
cout << a.first << " " << a.second << endl;
});
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
c:\qt\qt5.2.0\tools\mingw48_32\lib\gcc\i686-w64-mingw32\4.8.0\include\c++\bits\stl_algo.h:5513: error: no match for 'operator-' (operand types are 'std::_List_iterator<std::pair<std::basic_string<char>, int> >' and 'std::_List_iterator<std::pair<std::basic_string<char>, int> >')
std::__lg(__last - __first) * 2, __comp);
^ …Run Code Online (Sandbox Code Playgroud) 在我的测试中
@LargeTest
@RunWith(AndroidJUnit4.class)
public class SimpleActicityTest {
@Rule
public ActivityTestRule<MainActivity> activityActivityTestRule =
new ActivityTestRule<>(MainActivity.class);
@Test
public void testActivity() throws Exception {
Activity a = activityActivityTestRule.getActivity();
Screenshot.snapActivity(activity).setName("s1").record();
}
Run Code Online (Sandbox Code Playgroud)
我有
ava.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.app.Instrumentation.getContext()' on a null object reference
at com.facebook.testing.screenshot.internal.ScreenshotImpl.getInstance(ScreenshotImpl.java:338)
at com.facebook.testing.screenshot.Screenshot.snapActivity(Screenshot.java:45)
at com.mobium.reference.activity.Util.takeScreenshot(Util.java:32)
at com.mobium.reference.activity.SimpleActicityTest.lambda$testLeftMenuTest$1(SimpleActicityTest.java:52)
at com.mobium.reference.activity.SimpleActicityTest.access$lambda$0(SimpleActicityTest.java)
at com.mobium.reference.activity.SimpleActicityTest$$Lambda$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5549)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
Run Code Online (Sandbox Code Playgroud)
faceebook的lib getInstance()的来源:
public static ScreenshotImpl getInstance() {
if(sInstance != …Run Code Online (Sandbox Code Playgroud) 我有一个3000字符串的文件(1个字符串 - 几个字).我需要把字符串读成一个QList.我怎样才能做到这一点?我尝试过以下方法:
1.txt
string
string2
Run Code Online (Sandbox Code Playgroud)
function()<=> MyList<<"string"<<"string2";
我想在抽象类构造函数中注入接口实现并在子类中使用它.
我有编译时错误:
Error:Gradle: Dagger does not support injection into private fields
Error:Gradle: Example.A cannot be provided without an @Provides-annotated method.
Error:Gradle: Example.B cannot be provided without an @Inject constructor or from an @Provides-annotated method.
Error:Gradle: Execution failed for task ':app:compileDemoDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Run Code Online (Sandbox Code Playgroud)
kotlin中的例子.
object Example {
interface IData {
fun foo() {
}
}
class Data : IData {
}
@Module
class DataModel {
@Provides
fun data(): IData = Data()
}
@Singleton …Run Code Online (Sandbox Code Playgroud) 我该如何更改此代码?
QString s="123";
QStringList *myList=new QStringList;
myList<<s;
Run Code Online (Sandbox Code Playgroud)
错误:
'operator <<'不匹配(操作数类型是'QStringList*'和'QString')
*myList<<s;
Run Code Online (Sandbox Code Playgroud)
也不起作用:myList为空,此后.