我试图从bar中检索foo1中的字符串,但getFoo()方法由于某种原因没有被读取。这是酒吧班。
class bar
{
final String foo1;
final String foo2;
final String foo3;
bar(String foo1, String foo2, String foo3)
{
this.foo1 = foo1;
this.foo2 = foo2;
this.foo3 = foo3;
}
String getFoo1(){
return foo1;
}
String getFoo2(){
return foo2;
}
String getFoo3(){
return foo3;
}
}
以下是尝试访问Foo1的代码
Map<String, bar> map = new HashMap<>();
map.put("main1", new bar("foo1", "foo2", "foo3"));
"main1".getFoo1();
答案 0 :(得分:5)
两个问题:首先,包括括号,例如String getFoo1() {
不是String getFoo1 {
。
其次,你不能只做"main1".getFoo1()
,你必须从地图中获取"main1"
条目:map.get("main1").getFoo1()
。
答案 1 :(得分:2)
您缺少方法名称中的'()'
试试这个:
class bar
{
final String foo1;
final String foo2;
final String foo3;
bar(String foo1, String foo2, String foo3)
{
this.foo1 = foo1;
this.foo2 = foo2;
this.foo3 = foo3;
}
String getFoo1(){
return foo1;
}
String getFoo2(){
return foo2;
}
String getFoo3(){
return foo3;
}
}
另外,你不能只做“主”.getFoo1(); 试试:
map.get("main1").getFoo1();
答案 2 :(得分:1)
这是不正确的
"main1".getFoo1();
因为getFoo1()
不是字符串的方法。
我认为你在寻找
map.get("main1").getFoo1();
这会将foo
对象从地图中取出,其关键字是 main1 。
答案 3 :(得分:1)
您正在字符串对象“main1”而不是bar对象上调用getFoo1方法。我认为你要做的是使用键“main1”从地图中获取值,然后调用getFoo1。像这样:map.get(“main1”)。getFoo1();
答案 4 :(得分:1)
您必须从地图中检索元素,然后才能访问它。上面的代码只访问java.lang.String类
上的方法 Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.ComponentModel
Imports System.Diagnostics
<Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute()> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
Dim loRequest As System.Net.HttpWebRequest
Dim loResponse As System.Net.HttpWebResponse
Dim loResponseStream As System.IO.Stream
Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
Dim laBytes(256) As Byte
Dim liCount As Integer = 1
Try
loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
loRequest.Timeout = 600000
loRequest.Method = "GET"
loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
loResponseStream = loResponse.GetResponseStream
Do While liCount > 0
liCount = loResponseStream.Read(laBytes, 0, 256)
loFileStream.Write(laBytes, 0, liCount)
Loop
loFileStream.Flush()
loFileStream.Close()
Catch ex As Exception
End Try
End Sub
Public Sub Main()
Dim url, destination As String
destination = Dts.Variables("Folder_Destination").Value.ToString + "\" + "Report_" + Dts.Variables("ReportParameter").Value.ToString + "_" + Format(Now, "yyyyMMdd") + ".xls"
url = "http://localhost:8080/ReportServer?/MyReports/SSIS_Execute_SSRS_Report&rs:Command=Render&Productkey=" + Dts.Variables("ReportParameter").Value.ToString + "&rs:Format=EXCEL"
SaveFile(url, destination)
Dts.TaskResult = ScriptResults.Success
End Sub
End Class