我无法理解下面的泛型代码是做什么的.我是仿制药的新手所以非常感谢我能得到的所有帮助!
Public abstract class AMetadata< C extends CMetadata, P extends PMetadata, R extends RMetadata> extends GEntityMetada<C>
{
// class does stuff here
}
Run Code Online (Sandbox Code Playgroud)
谁能解释这些课程是如何相关的?
根据我的理解一个默认的构造函数初始化对象为默认值的状态,所以如果我提供一个明确的无参数的公共构造这样又如何,因为在这种情况下,默认的是d和e仍然得到初始化为零值不调用构造函数.
public class B extends A{
private int d;
private int e;
public B() {
System.out.println(d);
System.out.println(e);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑::默认构造函数做的唯一事情就是调用super()然后如果我在这里有一个明确提到的构造函数,A有一个受保护的变量,说c在其构造函数中初始化为17.super()因为我正在使用自己的构造函数,所以我是不是应该明确地要求能够看到这种变化?为什么B仍然通过继承得到17的值?
所以,如果我有一个数字1和另一个数字2 ..两个整数,我的方法是通过使用按位运算添加两个数字来纠正的吗?任何测试用例都会出错吗?
public int add(int number1, int number2)
{
int carry = (number1&number2)<<1;
int sum = number1^number2^carry;
return sum;
}
Run Code Online (Sandbox Code Playgroud) 下面的代码试图将随机值插入循环队列并将其删除.但是,存在一些同步问题.我知道我可以使用更高级别的例程,我将为生产代码执行此操作,但我很好奇为什么这不起作用?我在这里错过了什么?
public class CircularQueue {
int count;
int rear;
int front;
Object lock = new Object();
int size;
int[] array;
CircularQueue(int size)
{
this.size= size;
array = new int[size];
}
void enqueue(int number) throws InterruptedException
{
if(isFull())
lock.wait();
synchronized(lock)
{
array[rear] = number;
System.out.println("Rear is:"+ rear+ "value is:"+number+"Size is:"+size);
rear = (rear+1)%size;
count++;
}
lock.notify();
}
void dequeue() throws InterruptedException
{
if(isEmpty())
lock.wait();
synchronized(lock)
{
int retVal = 0;
retVal = array[front];
System.out.println("Front is:"+ front+ "value is:"+retVal);
front = (front+1)%size; …Run Code Online (Sandbox Code Playgroud) 我想用下面列出的另一个字符串替换字符串中的第一个空格字符.该单词可能包含许多空格,但只需要替换第一个空格.我试过下面的正则表达式,但它不起作用......
Pattern inputSpace = Pattern.compile("^\\s", Pattern.MULTILINE);
String spaceText = "This split ";
System.out.println(inputSpace.matcher(spaceText).replaceAll("&emsp;"));
Run Code Online (Sandbox Code Playgroud)
编辑::这是我正在使用的外部API,我有约束,我只能使用"replaceAll"..
我知道有一种更简单的方法可以让一些字符串成为回文,但是我想用库函数来尝试,我想出了下面的代码.
public boolean isPalindrome1(String input)
{
int length = input.length()/2;
if(input.length()%2!=0)
{
length = length + 1;
}
return(input.substring(0,length).equals(new StringBuilder(input.substring(length, input.length())).reverse().toString()));
}
Run Code Online (Sandbox Code Playgroud)
我试图检查一半的字符串是否等于另一半的反向.但它变得混乱了奇数和偶数长度.有人可以在这里指出纠正,它将适用于奇数,偶数长度以及空字符串和长度为1的字符串.
(W[AY]|C[AO])(\\s+\\d{5})
Run Code Online (Sandbox Code Playgroud)
因此,这当前解析以W或C开头的状态,然后是邮政编码.但是,它将所有这些作为一个组返回,如示例WA 98121 CA 56679将返回组1是WA 98121而组2是CA 56679.
如何解决此问题以在group1 WA group2 98121 group3 CA group4 56679中检索
为什么编译器会在这里抱怨?它不允许我Wrapper在main中创建一个对象.MyList是一个单独的类.我该如何创建它?
public class BinaryTree {
Node root;
class Wrapper {
MyList.Node node;
}
class Node {
Integer value;
Node left;
Node right;
Node(int value) {
this.value = value;
}
}
public static void main() {
MyList list = new MyList();
Wrapper w = new Wrapper();
w.node = list.getHead();
}
}
Run Code Online (Sandbox Code Playgroud) 我想写一个正则表达式,可以删除围绕[分]的括号
String input1 = "this is a [cent] and [cent] string"
String output1 = "this is a cent and cent string"
Run Code Online (Sandbox Code Playgroud)
但如果它嵌套如下:
String input2="this is a [cent[cent] and [cent]cent] string"
String output2="this is a cent[cent and cent]cent string"
Run Code Online (Sandbox Code Playgroud)
我只能在字符串上使用replaceAll,所以如何在下面的代码中创建模式?更换字符串应该是什么?
Pattern rulerPattern1 = Pattern.compile("", Pattern.MULTILINE);
System.out.println(rulerPattern1.matcher(input1).replaceAll(""));
Run Code Online (Sandbox Code Playgroud)
更新:嵌套括号格式正确,只有两个级别,如案例2.
编辑:如果这是字符串"[<centd>[</centd>]purposes[<centd>]</centd>]"; 那么OUPTUT应该是<centd>[</centd> purposes <centd>]</centd>..基本上如果括号在centd开头和结束之间留在那里或者删除
我有一个很大的疑问.我想在这里找到一个不重复的字符串的第一个字符.例如,对于下面的输入应该返回'c'.所以这就是我计划这样做的方式.但是我注意到remove方法希望删除索引为98而不是删除对象"a".如何强制它删除对象"a"而不是从索引中删除?
为什么这不起作用?
我该怎么做才能改变这个?
ArrayList总是保证按顺序存储东西吗?
public void findStartingLetter()
{
String[] array={"a","b","c","d","b","a","d","d","d"};
List<Character> list = new ArrayList<Character>();
for(String i:array)
{
if(list.contains(i.charAt(0)))
list.remove(i.charAt(0));
else
list.add(i.charAt(0));
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
性能方面是O(n)函数吗?