首页 \ 问答 \ 如果不同的Java泛型类型参数具有相同的名称,为什么可以分配不同的类型?(If different Java generic type parameter have the same name, why it can be assigned different types?)

如果不同的Java泛型类型参数具有相同的名称,为什么可以分配不同的类型?(If different Java generic type parameter have the same name, why it can be assigned different types?)

在oracle的官方java文档Type Inference章节中,有一个例子是这样的:

static <T> T pick(T a1, T a2) { return a2; }  
Serializable s = pick("d", new ArrayList<String>());

在这种情况下,类型参数是T,但通过了两种不同的类型,a1的类型是不是应该与a2相同?


In oracle's official java document, Type Inference chapter, there's an example like this:

static <T> T pick(T a1, T a2) { return a2; }  
Serializable s = pick("d", new ArrayList<String>());

In this case the type parameters are T but was passed two different type, shouldn't a1's type be the same as a2?


原文:https://stackoverflow.com/questions/47624283
更新时间:2022-02-05 16:02

最满意答案

waitFor函数接受选择器,函数或超时。 如果你想看看url是否等于某个东西,那就为它写一个函数。 将url作为参数传递,以便在浏览器上下文中阅读它。

const url = await page.url();
await page.waitFor((url)=> url === 'http://localhost:3000/blogs', url); // <-- use a function

您也可以使用内置代码构建的浏览器等待url匹配。

await page.waitFor(()=> location.href === 'http://localhost:3000/blogs');

请注意,由于您正在使用===来匹配字符串,因此请确保包含http://因为location.href将使用协议输出网址。

如果你想使用笑话,那么你可以使用expect并将其包装在一个块中。

it('should contain specific url', async () => {
    const url = await page.url();
    expect(url).toContain('localhost:3000/blogs');
});

这是一个供玩笑和木偶一起使用的文件。


The waitFor function accepts a selector, function or timeout. If you want to see if url is equal to something, then write a function for it. Pass the url as an argument so you can read it within the browser context.

const url = await page.url();
await page.waitFor((url)=> url === 'http://localhost:3000/blogs', url); // <-- use a function

Also you can use browsers built in code to wait for url to match.

await page.waitFor(()=> location.href === 'http://localhost:3000/blogs');

Note, since you are using === to match a string, make sure to include http:// since location.href will output the url with the protocol.

If you want to use jest, then you can use expect and wrap it in a it block.

it('should contain specific url', async () => {
    const url = await page.url();
    expect(url).toContain('localhost:3000/blogs');
});

Here is a document for jest and puppeteer together.

相关问答

更多
  • 目前无法将Puppeteer与Cloud Functions结合使用,因为运行部署代码的服务器实例缺少Puppeteer所需的共享库。 你可以在这个GitHub问题中阅读 。 也看到这个问题 。 It's currently not possible to use Puppeteer with the Cloud Functions node 6 runtime because the server instances that run deployed code are lacking a shared ...
  • 在最基本的层面上,POM声明每个页面都有自己的类,其中包含与该页面交互的实用程序方法。 为了通过Puppeteer实现这一点,我们使用ES6类来创建包含各自页面的实用程序方法的类。 文件夹结构 test/ main.js pages/ - HomePage.js - CartPage.js - ProductDetailPage.js HomePage.js export default class HomePage { constructor(page) { ...
  • 你的Object.keys回调函数也需要使用async以便在里面使用await。 尝试改变如下 Object.keys(TEAM['premier_league']).forEach( async function(key) { // Go To Team URL await page.goto(TEAM['premier_league'][key]['url']) }); 希望能帮助到你 Your Object.keys callback function need to use a ...
  • 当底层线程对象在操作系统层终止时, TThread.WaitFor()等待线程句柄( TThread.Handle属性)发出信号。 当您的Execute()方法退出后(并且在TThread.DoTerminate()被调用并退出后) TThread调用Win32 API ExitThread()函数时,会发生此信号。 您所描述的内容听起来像是遇到了阻止您的Execute()方法正确退出的死锁,即使您可能已通知FStopEvent停止了您的循环。 鉴于你已经显示的代码,这意味着要么WaitForMultipl ...
  • 在Runtime#exec完成一个过程后,有时需要一些时间来完成IO操作。 因此,在Process#waitFor之后尝试使用Thread#sleep进行一些延迟,以便让IO处理完成。 然后尝试阅读目标文件。 希望这可以帮助。 Sometimes it take time to complete IO operations after finishing a process by Runtime#exec. so try putting some delay using Thread#sleep after ...
  • 你正试图迭代jQuery列表。 您应该将.forEach()替换为等价于.each() jQuery 。 You are trying to iterate over jQuery list. You should replace .forEach() with jQuery equivalent .each().
  • waitFor函数接受选择器,函数或超时。 如果你想看看url是否等于某个东西,那就为它写一个函数。 将url作为参数传递,以便在浏览器上下文中阅读它。 const url = await page.url(); await page.waitFor((url)=> url === 'http://localhost:3000/blogs', url); // <-- use a function 您也可以使用内置代码构建的浏览器等待url匹配。 await page.waitFor(()=> locat ...
  • 正如您在waitFor()代码中看到的waitFor() ,每250毫秒调用一次testFx函数。 该函数应该只包含实际的检查代码而不包含加载代码。 只需将testFx includeJs()调用移出testFx函数即可。 另请注意, testFx函数必须返回示例中未包含的内容,因此它总是未定义并在一段时间后超时。 page.open("http://example.com", function (status) { if (status !== "success") { conso ...
  • 大部分时间都有空白,因为我们作为开发人员喜欢我们的缩进。 尝试检查HTML中是否包含该元素: return document.querySelector('...').innerHTML.indexOf('tocijan') != -1; 如果这不起作用,请检查元素是否在iframe中。 您需要使用casper.withFrame()专门切换到iframe。 Most of the time there is whitespace, because we as developers love our in ...
  • 此页面通过创建逗号分隔的字符串并强制浏览器通过设置数据类型来下载它来下载csv let uri = "data:text/csv;charset=utf-8," + encodeURIComponent(content); window.open(uri, "Some CSV"); 这在chrome上打开一个新选项卡。 您可以使用此事件并将内容物理下载到文件中。 不确定这是否是最佳方式,但效果很好。 const browser = await puppeteer.launch({ headless: ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)