Questions tagged «java»

Java是一种流行的高级编程语言。如果您在使用或理解语言本身时遇到问题,请使用此标签。这个标签很少单独使用,最常与[spring],[spring-boot],[jakarta-ee],[android],[javafx],[gradle]和[maven]结合使用。

4
Java反射中的getFields和getDeclaredFields有什么区别
我对使用Java反射时的getFields方法和getDeclaredFields方法之间的区别感到困惑。 我读到它getDeclaredFields使您可以访问该类的所有字段,并且 getFields只返回公共字段。如果是这样,您为什么不总是使用getDeclaredFields? 有人可以详细说明一下,并解释两种方法之间的区别,以及何时/为什么要在另一种方法上使用一种方法吗?
194 java  reflection 



27
NoClassDefFoundError-Eclipse和Android
我在尝试运行一个Android应用程序时遇到问题,直到向其构建路径添加第二个外部库为止,它运行良好。由于添加了scoreninja jar,当我尝试运行应用程序时,现在出现了NoClassDefFoundError。 这是消息: 02-11 21:45:26.154: ERROR/AndroidRuntime(3654): java.lang.NoClassDefFoundError: com.scoreninja.adapter.ScoreNinjaAdapter 由于所有的构建脚本都是由Android工具生成的(?),所以我不确定除了清理,重建或重新启动Eclipse外我还能做些什么(我已经尝试了全部三个)。有人知道我该如何修改吗?
193 java  android  eclipse  ant  build 


10
什么时候应该用Java调用System.exit
在Java中,System.exit(0)以下代码有或没有什么区别? public class TestExit { public static void main(String[] args) { System.out.println("hello world"); System.exit(0); // is it necessary? And when it must be called? } } 该文档说:“此方法永远不会正常返回。” 这是什么意思?
193 java  exit 

8
Java:如何从泛型类型获取类文字?
通常,我见过人们像这样使用类文字: Class<Foo> cls = Foo.class; 但是,如果类型是通用类型,例如List,该怎么办?这可以正常工作,但由于应将List参数化,因此发出警告: Class<List> cls = List.class 那么为什么不添加一个<?>呢?好吧,这会导致类型不匹配错误: Class<List<?>> cls = List.class 我想像这样的事情会起作用,但这只是一个普通的语法错误: Class<List<Foo>> cls = List<Foo>.class 我如何获得Class<List<Foo>>静态信息,例如使用类文字? 我可以使用@SuppressWarnings("unchecked"),以摆脱在第一个例子中所造成的非参数使用列表,警告的Class<List> cls = List.class,但我宁愿不要。 有什么建议?
193 java  generics  class  literals 

9
为什么在字符串后附加“”会节省内存?
我说了一个变量,里面有很多数据String data。我想通过以下方式使用此字符串的一小部分: this.smallpart = data.substring(12,18); 经过数小时的调试(使用内存可视化器),我发现objects字段smallpart记住了的所有数据data,尽管它仅包含子字符串。 当我将代码更改为: this.smallpart = data.substring(12,18)+""; ..问题解决了!现在我的应用程序现在只占用很少的内存! 那怎么可能?谁能解释一下?我认为this.smallpart一直在引用数据,但是为什么呢? 更新:那 我怎么清除大字符串?data = new String(data.substring(0,100))会做这件事吗?


9
如何使用spring-data-jpa更新实体?
这个问题几乎说明了一切。使用JPARepository如何更新实体? JPARepository只有一个save方法,它不会告诉我它是否实际上是在创建或更新。例如,我插入一个简单的对象数据库的用户,其中有三个领域:firstname,lastname和age: @Entity public class User { private String firstname; private String lastname; //Setters and getters for age omitted, but they are the same as with firstname and lastname. private int age; @Column public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } @Column …

7
在ExecutorService的提交和ExecutorService的执行之间选择
如果返回值与我无关,我应该如何在ExecutorService的 Submit或execute之间进行选择? 如果同时测试两者,则除了返回的值外,我看不到其他任何差异。 ExecutorService threadExecutor = Executors.newSingleThreadExecutor(); threadExecutor.execute(new Task()); ExecutorService threadExecutor = Executors.newSingleThreadExecutor(); threadExecutor.submit(new Task());


22
如何更改新材质主题中后退箭头的颜色?
我已经将SDK更新为API 21,现在“后退/向上”图标是一个指向左侧的黑色箭头。 我希望它是灰色的。我怎样才能做到这一点? 例如,在Play商店中,箭头为白色。 我这样做是为了设置一些样式。我已经习惯@drawable/abc_ic_ab_back_mtrl_am_alpha了homeAsUpIndicator。该可绘制对象是透明的(仅Alpha),但是箭头显示为黑色。我不知道是否可以像在电视机上一样设置颜色DrawerArrowStyle。或者,如果唯一的解决方案是创建my @drawable/grey_arrow并将其用于homeAsUpIndicator。 <!-- Base application theme --> <style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item> <item name="actionBarStyle">@style/MyActionBar</item> <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> <item name="homeAsUpIndicator">@drawable/abc_ic_ab_back_mtrl_am_alpha</item> <item name="android:homeAsUpIndicator" tools:ignore="NewApi">@drawable/abc_ic_ab_back_mtrl_am_alpha</item> </style> <!-- ActionBar style --> <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid"> <item name="android:background">@color/actionbar_background</item> <!-- Support library compatibility --> <item name="background">@color/actionbar_background</item> </style> <!-- Style for the navigation drawer …

2
CompletableFuture,Future和RxJava的Observable之间的区别
我想知道的区别 CompletableFuture,Future和Observable RxJava。 我所知道的都是异步的,但是 Future.get() 阻塞线程 CompletableFuture 提供回调方法 RxJava Observable--- CompletableFuture与其他好处相似(不确定) 例如:如果客户端需要进行多个服务调用,并且当我们使用Futures(Java)时Future.get()将依次执行...希望了解它在RxJava中的效果如何。 并且文档http://reactivex.io/intro.html说 使用Future来最佳地组合条件异步执行流是困难的(或者是不可能的,因为每个请求的延迟在运行时会有所不同)。当然可以这样做,但是很快就会变得复杂(因此容易出错),或者过早地在Future.get()上阻塞,这消除了异步执行的好处。 真的很想知道如何RxJava解决这个问题。我发现很难从文档中了解。

7
从Java字符串中删除✅,🔥,✈,♛和其他此类表情符号/图像/符号
我有一些带有各种不同表情符号/图像/符号的字符串。 并非所有字符串都是英语的-其中一些是其他非拉丁语言的,例如: ▓ railway?? → Cats and dogs I'm on 🔥 Apples ⚛ ✅ Vi sign ♛ I'm the king ♛ Corée ♦ du Nord ☁ (French) gjør at både ◄╗ (Norwegian) Star me ★ Star ⭐ once more 早上好 ♛ (Chinese) Καλημέρα ✂ (Greek) another ✓ sign ✓ добрай …
192 java  string  emoji 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.