小编Kas*_*sun的帖子

方法模糊不清 - 为什么不解决

public class Animal {}

public class Bird extends Animal {}

public class Mamal extends Animal {}

public class Human extends Mamal {}

public class Main {

    public void Hungry(Mamal mamal){
        System.out.println("Mammal");
    }   
    public void Hungry(Human human){
        System.out.println("Human");        
    }
    public void Hungry(Bird bird){
        System.out.println("Bird");
    }
    public static void main(String a[]){
        Main main = new Main();
        main.Hungry(null);
}
Run Code Online (Sandbox Code Playgroud)

编译器说,Hungry(Mamal)的方法含糊不清.我希望执行"人类"方法,因为它是最低级别.我没有从http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12找到歧义的原因.

java

6
推荐指数
1
解决办法
596
查看次数

差异上下文:property-placeholder VS @Configuration @PropertySource classpathproperties

我需要知道以下两种加载属性文件的方法之间的区别.

方法1

 <context:property-placeholder location="classpath:constants.properties"/>
Run Code Online (Sandbox Code Playgroud)

方法2

<context:component-scan base-package="com.snippets.enterprise"/>

package com.snippets.enterprise;

@Configuration
@PropertySource("classpath:/constants.properties")
public class SpringConfig  {}
Run Code Online (Sandbox Code Playgroud)

我在方法中看到两个键和值在加载应用程序上下文时可用.但在

当应用程序上下文加载时,属性的一个键不可用,它说

找不到密钥.请让我知道这两种方法的区别.

  1. 使用应用程序上下文加载属性文件时.

  2. 键时,属性文件的值在容器中初始化.

spring

5
推荐指数
1
解决办法
2754
查看次数

Ant配置 - debuglevel属性var line和source的含义

您能否解释一下Apache Ant中调试级别属性var,行和源的含义.很明显,这有助于生成帮助属性debug = true的所有调试信息.

  1. 定义debuglevel ="lines,vars,source"的目的是什么?这会限制调试信息吗?

  2. 如果每个值1.lines 2. vars 3. source?

  3. 我是否需要启用调试才能使此属性有效?

规范说,

要附加到-g命令行开关的关键字列表.除现代,经典(ver> = 1.2)和jikes外,所有实现都会忽略这一点.合法值为none或以逗号分隔的以下关键字列表:lines,vars和source.如果未指定debuglevel,则默认情况下不会将任何内容附加到-g.如果未打开调试,则将忽略此属性.

ant javac

4
推荐指数
2
解决办法
5991
查看次数

无法找到XML架构命名空间的Spring NamespaceHandler [http://cxf.apache.org/jaxws]

我需要将Spring与CXF 3.0版集成.CXF库位于类路径中.我在尝试访问Web服务时收到错误"无法找到用于XML架构命名空间的Spring NamespaceHandler [http://cxf.apache.org/jaxws]".这可能是错的?Schema url是否有机会改变?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
Run Code Online (Sandbox Code Playgroud)

spring web-services cxf

3
推荐指数
1
解决办法
4868
查看次数

如何使用 Gson 从 JSON 输出访问特定元素

我只需要访问“formatted_address”的值:“4 Place du Louvre, 75001 Paris, France”属性。请帮助我如何使用 com.google.gson.Gson 和 java 执行此操作,而无需为整个结构维护单独的 POJO 类。

\n\n
{\n    "results": [{\n        "address_components": [{\n            "long_name": "4",\n            "short_name": "4",\n            "types": ["street_number"]\n        }, {\n            "long_name": "Place du Louvre",\n            "short_name": "Place du Louvre",\n            "types": ["route"]\n        }, {\n            "long_name": "Paris",\n            "short_name": "Paris",\n            "types": ["locality", "political"]\n        }, {\n            "long_name": "Paris",\n            "short_name": "75",\n            "types": ["administrative_area_level_2", "political"]\n        }, {\n            "long_name": "\xc3\x8ele-de-France",\n            "short_name": "IDF",\n            "types": ["administrative_area_level_1", "political"]\n        }, {\n            "long_name": "France",\n            "short_name": "FR",\n            "types": ["country", "political"]\n        }, {\n            "long_name": "75001",\n            "short_name": "75001",\n            "types": …
Run Code Online (Sandbox Code Playgroud)

java json gson

2
推荐指数
1
解决办法
7811
查看次数

类级和对象级锁同步

class MyClass
{
    public synchronized void print() {}

    public static synchronized void buffer() {}
}
Run Code Online (Sandbox Code Playgroud)

使静态对象同步会生成一个 CLASS 级别的对象,其中只有一个线程可以访问它。该类具有静态和非静态同步方法。

  1. 其他线程(线程-B)可以通过对象锁访问非静态同步方法(),而另一个线程(线程-A)使用静态同步(获取类级锁)方法吗?

  2. 我希望在 (Thread-B) 释放锁之前,没有线程访问任何静态同步方法。

java static multithreading

1
推荐指数
1
解决办法
5163
查看次数

标签 统计

java ×3

spring ×2

ant ×1

cxf ×1

gson ×1

javac ×1

json ×1

multithreading ×1

static ×1

web-services ×1