gpt4 book ai didi

java - AWS 源代码错误?

转载 作者:行者123 更新时间:2023-11-30 10:35:14 24 4
gpt4 key购买 nike

在我们的代码中,我们从 sqs 队列中删除一条消息并获取 deletResponse

String deleteResponse = sqsClient.deleteMessage(simBridge2ESBUrl, message.getReceiptHandle()).toString();

此调用后消息被删除,但 deleteResponse 始终为 {}。所以我们检查了源代码,发现 DeleteMessageResult::toString 函数只返回 {}

以下是 AWS 源代码。 toString()hashCode() 函数看起来很奇怪。源代码有错误还是我做错了?谢谢。

/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights
* Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amazonaws.services.sqs.model;

import java.io.Serializable;

/**
*
*/
public class DeleteMessageResult implements Serializable, Cloneable {

/**
* Returns a string representation of this object; useful for testing and
* debugging.
*
* @return A string representation of this object.
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("}");
return sb.toString();
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;

if (obj instanceof DeleteMessageResult == false)
return false;
DeleteMessageResult other = (DeleteMessageResult) obj;
return true;
}

@Override
public int hashCode() {
final int prime = 31;
int hashCode = 1;

return hashCode;
}

@Override
public DeleteMessageResult clone() {
try {
return (DeleteMessageResult) super.clone();
} catch (CloneNotSupportedException e) {
throw new IllegalStateException(
"Got a CloneNotSupportedException from Object.clone() "
+ "even though we're Cloneable!", e);
}
}
}

最佳答案

从编程的角度来看,toString() 是正确编写的。想想这个函数做了什么:

A string representation of this object.

因为 DeleteMessageResult 类没有属性,所以没有什么可以返回的。这同样适用于 hashCode()DeleteMessageResult 的两个对象始终相同,因此它们每次都具有相同的哈希值。

话虽如此,我确实认为 DeleteMessageResult 应该包含具有唯一 RequestIdResposeMetadata,如 API reference 中所示:

<DeleteMessageResponse>
<ResponseMetadata>
<RequestId>
b5293cb5-d306-4a17-9048-b263635abe42
</RequestId>
</ResponseMetadata>
</DeleteMessageResponse>

所以,是的,这个类可以(可能,应该)被修补以完全支持 SQS API。

关于java - AWS 源代码错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41307904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com