首页 > 其他分享 >2th Feb

2th Feb

时间:2023-02-02 22:58:29浏览次数:47  
标签:own Feb just object 2th interface Java

【1】why Java接口作为参数传递
https://stackoverflow.com/questions/2575429/interface-as-a-method-parameter-in-java

There are many examples in the Java standard API, especially in the collections framework. For example, Collections.sort() can sort anything that implements the List interface (not just ArrayList or LinkedList, though implementing your own List is uncommon) and whose contents implement the Comparable interface (not just String or the numerical wrapper classes - and having your own class implement Comparable for that purpose is quite common).

It's not the interface "object" being passed to the method, still just a regular object. It's just a way of saying "this parameter will accept any object that supports this interface". It's equivalent to accepting some object of a base class type, even if you're passing in a subclass.

标签:own,Feb,just,object,2th,interface,Java
From: https://www.cnblogs.com/YeYangzhi/p/17087663.html

相关文章

  • ACSX: Jan&Feb, 2023
    飞花有\(n(n\le2\times10^5)\)张卡牌,正面\(a_i\),反面\(b_i\),所有\(1\lea_i,b_i\le2n\)且互不相同。你可以选择翻任意张卡牌,翻完后可不耗代价任意重排,问最少翻......
  • 【补档 12th Jan】子集2
    【补档12thJan】子集2给你一个整数数组nums,其中可能包含重复元素,请你返回该数组所有可能的子集(幂集)。解集不能包含重复的子集。返回的解集中,子集可以按任意顺序......
  • [补档 12th Jan] 子集
    [补档12thJan]78子集给你一个整数数组nums,数组中的元素互不相同。返回该数组所有可能的子集(幂集)。解集不能包含重复的子集。你可以按任意顺序返回解集。输......
  • 【补档 12th Jan】1807 替换字符串中的括号内容(每日一题)
    【补档12thJan】1807替换字符串中的括号内容(每日一题)给你一个字符串s,它包含一些括号对,每个括号中包含一个非空的键。比方说,字符串"(name)is(age)yearsold"中,有......
  • P2894 [USACO08FEB]Hotel G
    \(P2894\)[\(USACO08FEB\)]\(Hotel\)\(G\)一、题目描述参考样例,第一行输入\(n,m\),\(n\)代表有\(n\)个房间,编号为\(1-\simn\),开始都为空房,\(m\)表示以下有\(m\)行操作......
  • [USACO22FEB] Sleeping in Class B
    好题分享——[USACO22FEB]SleepinginClassB洛谷题目链接题面翻译\(T\)组数据,每组给定一个长度为\(N\)的数组\(a_1,a_2,\dotsb,a_n\)。每次操作可选择两个......
  • P2895 [USACO08FEB]Meteor Shower S
    P2895[USACO08FEB]MeteorShowerS#include<iostream>#include<cstring>#include<queue>usingnamespacestd;constintN=310;intx,y,t;intg[N][N];......
  • P6147 [USACO20FEB] Delegation G
    \(\mathcalLink\)非常套路,神似NOIp2018D1T3。首先,只有能整除\(n-1\)的数才有可能。然后考虑判定。一个节点只能向上延伸出一条链,所以其他的链必须两两匹配掉。考虑......
  • USACO 2018 Feb 题解
    USACO2018FebSolution目录USACO2018FebSolution更好的阅读体验戳此进入题面Luogu链接LG-P4266[USACO18FEB]RestStopsS题面ExamplesSolutionCodeLG-P4264[USAC......
  • LG-P4264 [USACO18FEB]Teleportation S 题解
    LG-P4264[USACO18FEB]TeleportationSSolution目录LG-P4264[USACO18FEB]TeleportationSSolution更好的阅读体验戳此进入题面SolutionCodeUPD更好的阅读体验戳此进入......