小编deH*_*aar的帖子

Java实例变量可访问性

Java中以下变量的可访问性有何不同?

public class Joe {
    public int a;
    protected int b;
    private int b;
    int c;
}
Run Code Online (Sandbox Code Playgroud)

我最感兴趣的是最后一个人在做什么.

java variables inheritance accessibility

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

在构建之前将jar添加到maven本地存储库

我有第三部分jar文件远程不存在项目目录中的文件,我想在执行mvn install时将此jar添加到本地存储库中,我当前的代码是这样做的

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>install-file</goal>
            </goals>
            <configuration>
                <groupId>myJar1.0</groupId>
                <artifactId>myJar1.0</artifactId>
                <version>1.0</version>
                <packaging>jar</packaging>
                <file>myJar1.0.jar</file>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

java maven

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

日期时间字符串中的“z”在不同的语言环境中是否有不同的输出?

不久前,我回答了一个关于如何从ZonedDateTime解析的String.
它一般有效,但在 OP 的系统和我的系统上有相同代码的不同输出,不知何故不再让我离开。

相关问题询问如何ZoneId从 a获取a ZonedDateTime,我提供了一种方法。诚然,这不是公认的答案,但似乎仍然值得某人点赞。

我的答案的特别之处在于'z'用于解析时间的模式中的String。有一个时区名称,用(澳大利亚中部标准时间)String表示时区。"Australia/Adelaide""... ACST"

当我解析它在我的系统和打印上/格式化ZonedDateTime使用DateTimeFormatter.ISO_ZONED_DATE_TIME,它打印的时间"America/Manaus"和已经提取ZoneId,它仍然是一个来自南美。OP 在我的回答下方的评论中指出,在他的系统上,至少有一个输出行显示了所需的/正确的ZoneId.

这怎么可能?系统默认语言环境对解析'z'in datetime有什么影响String吗?

这是我在问题中的回答的代码加上我的输出ZoneId.systemDefault()

public static void main(String args[]) throws Exception {
    String time = "2 Jun 2019 03:51:17 PM ACST";
    String pattern = "d MMM yyyy hh:mm:ss a z"; // z detects the time zone (ACST here) …
Run Code Online (Sandbox Code Playgroud)

java timezone java-time zoneddatetime

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

HashSet问题 - equals和hashCode包含的工作方式与我预期的不同

我有以下代码:

class IncidentTag:
     def __init__(self,tag):
        self.tag = tag
     def equals(self,obj):
        return self.tag.equals(obj.tag)
     def hashCode(self):
        return self.tag.hashCode()

from java.lang import String
from java.util import HashMap
from java.util import HashSet

tag1 = IncidentTag(String("email"))
tag1copy = IncidentTag(String("email"))
tag2 = IncidentTag(String("notemail"))

print tag1.equals(tag1copy)
print tag2.equals(tag2)

print "Now with HashSet:"

hSet = HashSet()
hSet.add(tag1)
hSet.add(tag2)

print hSet.contains(tag1)
print hSet.contains(tag2)
print hSet.contains(tag1copy)
Run Code Online (Sandbox Code Playgroud)

输出为:1 1现在使用HashSet:1 1 0

但是,我原本期望最后一行也是真的(1).是否有一些我不知道的明显事物.

(是的,我知道我的equals方法和hashcode方法没有考虑到一些问题...它们是故意简单的,但如果问题导致这个问题,请告诉我)

java collections jython hashset

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

如果else语句有4个结果但只有2个似乎有效

所以我正在研究我的第一个关于编程的项目.从未尝试过任何编程.我想让它能够在4个不同的结果和默认函数之间进行选择,但它似乎只能在if语句和第二个if语句之间进行选择.我做错了什么?

private void userStandby () {                                                             

    System.out.println("What do you want to set your membershipstatus to");                       
    System.out.println("1) Active \n2) Standby");                                              
    int newchange = input.nextInt();                                                          

    ((Medlem) currentUser).setStatus(newchange);                                             

    if (((Medlem) currentUser).getStatus() == 1 && newchange == 1) {                         
        System.out.println("Your membership is already active");                                                                                                                
    } else if (((Medlem) currentUser).getStatus() == 1 && newchange == 2)  {                  
        System.out.println("Your membership is now on standby");                              
    } else if (((Medlem) currentUser).getStatus() == 2 && newchange == 2) {                   
        System.out.println("Your membership is already on standby");                      
    } else if (((Medlem) …
Run Code Online (Sandbox Code Playgroud)

java if-statement

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

如何Activator.CreateInstance一个没有构造函数的类型?

例如:

class TestType
{
   public int a;
   public int b;
}

TestType obj = Activator.CreateInstance(typeof(TestType), 1, 2) as TestType;
Run Code Online (Sandbox Code Playgroud)

然后obj.a==1obj.b==2?有人知道如何解决我的问题吗?

c#

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

加载构造函数时值为null

Properties我没有在构造函数内部使用,而是看到@Value注解可以解决问题。

它可以在我拥有的另一个实现中工作,但在这里没有

控制器:

@Autowired
private Customer customer;
Run Code Online (Sandbox Code Playgroud)

我的课

@Service
public class Customer {

    /** The soap GW endpoint. */
    @Value("${soapGWEndpoint}")
    private String soapGWEndpoint;

    /** The soap GW app name. */
    @Value("${soapGWApplName}")
    private String soapGWAppName;

    /** The soap GW user. */
    @Value("${generic.user}")
    private String soapGWUser;

    /** The soap GW password. */
    @Value("${generic.user.password}")
    private String soapGWPassword;

    public Customer () {
        // All parameters are null:
        login(soapGWEndpoint, soapGWAppName, soapGWUser, soapGWPassword);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是它们位于application.properties文件中。

为什么在这种情况下我不能使用@Value?

java spring

3
推荐指数
2
解决办法
484
查看次数

流映射以查找最新密钥的值

我有Map<Element, Attributes>以下(示例)类和枚举的实例,其中我想获取最新密钥的值stream().最近的键可以由creationTime类的属性确定,Element并且相应的值Map只是一个enum值:

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Element implements Comparable<Element> {

    String abbreviation;
    LocalDateTime creationTime;

    public Element(String abbreviation, LocalDateTime creationTime) {
        this.abbreviation = abbreviation;
        this.creationTime = creationTime;
    }

    public String getAbbreviation() {
        return abbreviation;
    }

    public void setAbbreviation(String abbreviation) {
        this.abbreviation = abbreviation;
    }

    public LocalDateTime getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(LocalDateTime creationTime) {
        this.creationTime = creationTime;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Comparable#compareTo(java.lang.Object) …
Run Code Online (Sandbox Code Playgroud)

java filter keyset java-stream

3
推荐指数
2
解决办法
59
查看次数

Kotlin:如何展平哈希图列表

如何在 Kotlin 中展平 s 列表HashMap

var listOfMaps: List<Map<String, String>> = listOf(mapOf("test" to "test1"), mapOf("test2" to "test3"), mapOf("test4" to "test5"))
Run Code Online (Sandbox Code Playgroud)

我想get:Map<String,String>与所有键值对

kotlin

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

如何正确覆盖 Kotlin 类中的 var?

我正在尝试覆盖类中的值。我有以下代码:

open class Balloon() {
    open var textSize: Float = 20f
    init {
        Log.i("textSize", textSize.toString())
    }
}
    
class BigBalloon(): Balloon() {
    override var textSize = 30f
}
Run Code Online (Sandbox Code Playgroud)

但是,日志会打印出这些值:

在此处输入图片说明

第一个日志来自Balloon(),第二个来自BigBalloon()0.0当我将其覆盖为 时,它如何打印30?我是否错误地实施了所有这些?

inheritance android class kotlin

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