为什么A-> B不会使List – > List ? 这不会消除对通配符的需求吗?

免责声明:我不是专业开发人员,我不打算成为一名开发人员。 关于Java的阅读书,因为我想尝试Android编程,没有任何以前的Java经验。 我正在读这本书 – 我更喜欢它。 我已经阅读了关于generics类的章节的一部分,到了他们提到通配符的地步,并且感到困惑。 如果B延伸A: List 不是 List的子类型(据我所知,它们完全相同) List List是List的子类型List List 后者允许编写接受generics类型参数的函数 – 例如List List 。 这样的函数会接受List或List 。 现在,对于我的问题: 以类似于C ++(以“模板”风格)的方式实现generics不是更简单吗? 这将使List和List两种不同的类型,这些类型将以预期的方式相关。 这也可以简单地在函数中声明你期望参数是List类型,这将允许List适合那里。 我猜测不仅仅是“我们讨厌C ++,让我们做出与众不同”这一点:)我很可能还不知道什么,这使得通配符成为一个非常有用的工具。 你对此有何看法? 编辑:如果您在答案中提到List ,请记住使用反引号,以避免被解释为HTML标记。

ant目标将战争部署到tomcat7 / webapps

我想使用ant target将刚刚创建的*.war (爆炸)部署到${TOMCAT_HOME}/webapps 。 组态 我的tomcat版本是7.0.37, tomcat-users.xml是: war.properties是: # War Build Properties package.dir=${basedir}/package war.exploded.dir=${deploy.dir}/war-ex # ——— Tomcat Settings ————— # FIXME : tomcat.url=http://localhost:8080/manager/text tomcat.url=http://localhost:8080/manager tomcat.username=tomcat tomcat.password=tomcat context-path=/eccount 我的deploy-war目标如下( tomcat-deploy.xml ): 问题 当我通过命令行命中ant deploy-war ,我得到以下exception: FileNotFoundException : http://localhost:8080/manager/deploy?path=%2Feccount&war=file%3A%2F%2FC%3A%5Ceccount%2Fdeploy%2Fwar-ex 但是,可以通过Web浏览器访问相同的路径file:///C:/eccount/deploy/war-ex 。 参考 在Tomcat 7.0.37中远程部署新应用程序 在Tomcat上部署war文件 Apache Ant如何将.war文件部署到Tomcat Tomcat 7的Catalina-Ant

使用JdbcBatchItemWriter更新重复键

spring批量为我的项目,我只是尝试从csv文件读取并将数据加载到数据库,使用JdbcBatchItemWriter作为编写器。 我正在寻找一种方法来告诉编写器插入一个新行,但是,在重复键(或重​​复的唯一标识符)更新行而不是失败。 我知道我可以直接在sql语句中执行此操作,但这将特定于Mysql,但我希望我的代码与DBMS无关。 这是我在java配置中的编写器声明 @Bean @StepScope public ItemWriter writerHeadingCollectionsToDb(DataSource datasource) { String sqlStatement = “INSERT INTO abcd(id, first_name, last_name, phone_number” + “VALUES (:id, :firstName, :lastName, :phoneNumber)”; JdbcBatchItemWriter itemWriter = new JdbcBatchItemWriter(); itemWriter.setSql(sqlStatement ); itemWriter.setDataSource(dataSource); itemWriter.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider()); return itemWriter; } 在此先感谢您的帮助

为什么生成的PDF在Internet Explorer中正常显示,而在FireFox或Chrome中却没有?

我使用lowagie / iTextPDF在Java中生成PDF并且在Firefox和Chrome中显示输出时出现问题,但IE8显示它们很好。 Firefox和Chrome显示乱码,如下所示: %PDF-1.4% 20 ob​​j streamx 1B1C #@ 0# Tm>}Zh nO?8 1 a y ӓB $ :9XC a. / f { $ o – $?ӨӨ^ c / ‘E j }WT / Y <? 5* endstream endobj 4 0 obj >> / MediaBox [0 0 612 1008] / Rotate 90 >> endobj 1 0 […]

如何从二维数组中查找索引

我要做的是打印二维数组中的最大数字,它是索引位置。 我能找到最大的数字,但我似乎无法弄清楚如何打印它的索引位置。 无论如何,这是我到目前为止所拥有的: public static void main(String[] args) { int[][] arr = {{4, 44, 5, 7, 63, 1}, {7, 88, 31, 95, 9, 6}, {88, 99, 6, 5, 77, 4}}; double max = arr[0][0]; for (int i = 0; i < arr.length; i++) { for (int j = 0; j max) { max = arr[i][j]; […]

我应该在这里使用全局变量吗?

为什么使用全局变量是个坏主意? 我想为所有要使用的类创建一个变量数组。 它将存储关键状态,因此不能设置为const(final)。 你能告诉我一些其他(正确的)如何做到这一点的方法吗?

使用Cassandra 3.x驱动程序进行Spring Boot

我使用Spring boot 1.3.8.RELEASE 。 要使用cassandra 3.x驱动程序,我尝试了类似下面的内容; org.springframework.boot spring-boot-starter-data-cassandra org.springframework.data spring-data-cassandra org.springframework.data spring-data-cassandra 1.4.0.RELEASE com.datastax.cassandra cassandra-driver-core com.datastax.cassandra cassandra-driver-dse com.datastax.cassandra cassandra-driver-core 3.1.0 但我得到错误; Caused by: java.lang.NoSuchMethodError: com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class; at org.springframework.data.cassandra.mapping.CassandraSimpleTypeHolder.(CassandraSimpleTypeHolder.java:62) ~[spring-data-cassandra-1.4.0.RELEASE.jar:?] 我在https://github.com/spring-projects/spring-boot/issues/5835尝试了这个原因,有一个post; 在Spring Data Cassandra 1.5(Ingalls)中采用Cassandra 3更改并不会对Spring Boot进行重大更改。 使用Boot 1.3.3和1.4.0-SNAPSHOT测试升级。 它不应该像上面那样吗? 我哪里错了? 注意:我正在尝试这个例子: https : //github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-cassandra

Swagger Gateway MicroService聚合

我正在使用SpringBoot开发一个微服务应用程序。 Gateway Microervice面向公众,它将请求重定向到特定的微服务(在不同的主机上运行)。 现在,我有多个微服务,每个微服务都使用Swagger公开了他们的API。 我们希望为公共客户聚合所有这些API Swagger文档。 我们已经合并的临时解决方案是,只为Gateway Service中的每个微服务复制了Swagger Annotated类。 这样做的正确方法是什么?

从java程序运行shell脚本时权限被拒绝

我正在尝试使用java程序运行我的shell脚本。 我得到以下exception。 java.io.IOException: Cannot run program “/home/builder/code/target/classes/idFetcher.sh”: java.io.IOException: error=13, Permission denied at java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at java.lang.Runtime.exec(Runtime.java:605) at java.lang.Runtime.exec(Runtime.java:443) at java.lang.Runtime.exec(Runtime.java:340) at script.InformationFetcher.main(InformationFetcher.java:26) 文件路径正确,文件存在于该位置。 这是我的代码 package script; import java.io.IOException; public class InformationFetcher { public InformationFetcher() { } public static void main(String[] args) { try { InformationFetcher informationFetcher = new InformationFetcher(); Runtime.getRuntime().exec(informationFetcher.getFilePath()); } catch (IOException e) { e.printStackTrace(); […]

j2me应用程序中的OutOfMemoryError

我在J2ME应用程序中获取OutOfMemoryException 。 如何找到导致此错误的原因? 以及如何防止出现此错误? 我发了一个http请求。 请求未完成时,屏幕显示加载图像(如浏览器在加载页面时显示)。 这是通过创建图像并重新绘制屏幕来完成的。 create image 1 – > repaint – > create image 2-> repaint-> create image 3 – > repaint – > create image 1-> repaint – >。 我注意到(使用wtk内存监视器)这消耗了太多的内存,而不是垃圾回收。 然后我尝试创建一个类图像池。 该类创建所有图像,然后显示它们。 创建图像1 – >创建图像2->创建图像3 – >重绘 – >重绘 – >重绘 – >重绘 – >重绘 – >。 第二种情况似乎没有内存消耗那么多。 (使用wtk内存监视器)。 但是,我认为(不确定是否这样)这两种方法都会导致这种OutOfMemoryException 。