RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-557913

Qwer's questions

Martin Hope
Qwer
Asked: 2024-11-23 03:20:57 +0000 UTC

方法重载、类型转换

  • 5

有一段代码:

public class Main_num {
    
    public static void num(Integer i) {
        System.out.println("num(Integer)");
    }
    public static void num(short i) {
        System.out.println("num(short)");
    }
    public static void num(long i) {
        System.out.println("num(long)");
    }
    public static void num(Object i) {
        System.out.println("num(Object)");
    }
    public static void num(int... i) {
        System.out.println("num(int...)");
    }

    public static void main(String[] args) {
        num(5);
    }

启动后,会显示num(long).其余方法为什么不被调用是可以理解的,但对我来说并不明显为什么程序将数字 5 识别为 long 而不是 Short 并调用相应的方法 (num(long i)) 而不调用 num(short i) )。有人可以解释一下吗?

java
  • 2 个回答
  • 23 Views
Martin Hope
Qwer
Asked: 2024-07-20 09:01:38 +0000 UTC

从互联网下载文件

  • 3

我正在编写一个网络程序;当我按下用户本地计算机上的按钮(很可能在下载文件夹中)时,应该保存客户端列表。现在我的桌面上保存文件的绝对路径已经写好了,如何更改该路径,使其对任何用户通用?

 File file = new File("C:\\Users\\Andrew\\Desktop\\client_data.txt");
        try (BufferedWriter writer = new BufferedWriter
                (new OutputStreamWriter
                        (new FileOutputStream(file), StandardCharsets.UTF_8))) {
            List<Client> list = (List<Client>) clientRepository.findAll();
            for (int i = 0; i < list.size(); i++) {
                writer.write(list.get(i).getId() + " " + list.get(i).getName() + " (" + list.get(i).getClStatus() + ") " + list.get(i).getGeneralNum() + ", " + list.get(i).getExtraNum1() + ", " + list.get(i).getExtraNum2() + '\n');
            }...
java
  • 1 个回答
  • 32 Views
Martin Hope
Qwer
Asked: 2024-02-11 02:43:51 +0000 UTC

数据库表属性与对象参数的关联

  • 6

我正在创建一个 Spring Web 应用程序,将信息存储在关系数据库中。如果我正确理解中继数据库中链接表的逻辑,那么每个对象(客户、订单、产品等)都应该有一个唯一的 id,通过它可以方便地链接它们;以简化的形式,它看起来像这样 在此输入图像描述

我是否正确理解数据库中表的属性和java中类对象的参数不必匹配?那些。我的类Order(表 1)很可能有一个类型字段Customer(Customer 对象有九个参数,其中之一是 id),但是当“链接”java 代码与数据库时,我不会将整个客户端传输到数据库表,但只有他的id。另外,告诉我,该类是否需要Customer有一个 id 参数,或者可以由数据库分配吗?我无法理解数据库和程序代码之间的功能差异。

public class Client {
private static int num = 1;
    private final int id;
    private String name;
    private long tel;
    private String comment;
    

    public Client (String name,long tel) {
        this.id = num++;
        this.name=name;
        this.tel=tel;
        this.comment=null;
       
    }
public class Ordering {
    private static int num = 1;
    private final int id;
    private Client client;
    private String product;
    private PriceOrder price;
  
    public Ordering(Client client, String product, int prepayment) {
        this.id = num++;
        this.client = client;
        this.product = product;
        this.price = new PriceOrder(prepayment);
    }
java
  • 1 个回答
  • 31 Views
Martin Hope
Qwer
Asked: 2024-02-09 23:28:43 +0000 UTC

自定义 IntelliJ IDEA 类图标

  • 5

谁能告诉我如何更改类、界面、enam 图标的设计?

在此输入图像描述

intellij-idea
  • 1 个回答
  • 32 Views
Martin Hope
Qwer
Asked: 2024-01-29 07:53:11 +0000 UTC

从后代类访问受保护的内部祖先类

  • 5

三个不同的包包含:

  • 接口(MyInterfaceInner);
  • 祖先类(GeneralClass),它有一个受保护的内部类(ProtectedClass);
  • 类是后继类(DerivativeClass)。

我无法在后代类中编写返回对祖先内部类的对象的引用的方法。这个想法建议创建一个 ProtectedClass 类public,在这种情况下一切正常。因为 由于修饰符protected将其访问权限扩展到其继承者(这似乎是我的情况),因此令人惊讶的是代码无法编译。谁能解释一下发生了什么事吗?

public interface MyInterfaceInner {
    void print();
}


public class GeneralClass {

    protected class ProtectedClass implements MyInterfaceInner {

        @Override
        public void print() {
            System.out.println("Как здорово, что все мы здесь сегодня собрались");
        }
    }
}


public class DerivativeClass extends GeneralClass {

    public ProtectedClass getProtectedClass() {
        GeneralClass g = new GeneralClass();
        // в этой строке код не компилируется
        GeneralClass.ProtectedClass p = g.new ProtectedClass();
        return p;
    }
}
java
  • 1 个回答
  • 25 Views
Martin Hope
Qwer
Asked: 2024-01-15 04:30:00 +0000 UTC

父类和子类中的静态方法

  • 8

有一段代码:

public class Coffee {
    String name="Кофе";

    public static void buyCoffee(Coffee coffee) {
        System.out.println("Вы купили " + coffee.name);
    }
}

public class Latte extends Coffee{
    String name = "Латте";

    public static void buyCoffee(Coffee coffee) {
        System.out.println("Вы купили " + coffee.name);
    }
}

import static filosofia.java.p212.inheritance.static_method.Latte.buyCoffee;

public class Main {
    public static void main(String[] args) {
      
        Latte latte = new Latte();
        buyCoffee(latte);
    }
} 

产生以下结果

Вы купили Кофе

我知道静态方法不支持多态行为,因此需要Вы купили Кофе对象的输出。Coffee coffee = new Latte()但为什么Latte latte = new Latte()它对 java 对象的反应就像它是 Coffee 类型的对象一样,尚不清楚。那些。如果没有创建该类的实例,Coffee程序仍将访问其字段。怎么会这样?

java
  • 2 个回答
  • 45 Views
Martin Hope
Qwer
Asked: 2024-01-02 00:34:38 +0000 UTC

字符串的逻辑运算符

  • 9

有一段代码:

String a = "Hello", b = "Hello";
System.out.println("a==b: " + a==b);
System.out.println("a!=b: " + a!=b);

其输出以下值:

false
true

我知道运算符==比较!=引用,因此输出结果 (false, true),但我不明白字符串值从 string 到"a==b: "哪里"a!=b: "。我认为这里与类型转换有关,但我无法完全理解它。有人可以更具体地解释一下吗?

java
  • 2 个回答
  • 55 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5